Saturday, May 23, 2020

Connecting to Dropbox API via POSTMAN

In this post, we will see how we can upload a file from your local system to Dropbox via API's. Dropbox provides API's, and we can invoke the APIs by passing the request (in this example, by passing the image in the request) and it should get attached in the Dropbox storage.

Step by Step Illustration:

#1 Login to dropbox by clicking here 
     #1.1. Create an app:
               - You would need to be signed-in.
               - Use the trial version for learning.
     #1.2. Once app is created, note "Generated access token". 
     #1.3 The above steps are self-explanatory

#2 Navigate to :
     #2.1 Locate your app created in the home screen.
     #2.2 Create a folder within your app. Ex: "Demo"

#3 Please note that Dropbox is providing API for clients 
    #3.1 Copy below CURL which we would be using in Step#4.2
    #3.2 Path to be provided with the folder created in step #2.
    #3.3 Observe that ACCESS_TOKEN
    #3.4 And also observe the endpoint URL of the Dropbox API
    #3.5 And the method we use here is POST.

curl -X POST \
 --header "Authorization: Bearer <ACCESS_TOKEN>" \
 --header "Dropbox-API-Arg: {\"path\": \"/Demo/HowToPega.png\"}" \
 --header "Content-Type: application/octet-stream" \
 --data-binary @UploadFile.png
Note: Documentation of Dropbox API:

#4 Open POSTMAN app (assuming it's already installed in your system. If not installed, please install it first and proceed with the next steps.
     #4.1 Click on Import (as highlighted in below screenshot)
     #4.2 Navigate to "Paste Raw text", paste the CURL given in step #3.1

#5 Observe the endpoint URL of the Dropbox API and the Headers
     #5.1 Authorization header value: replace <ACCESS TOKEN> with the generated token collected in Step#1.2

#6 Navigate to Body tab of the request, and select binary as an option and Choose File to select the file you would like to upload

#7 Now we are all good with the endpoint URL, Authorization headers and the body (where file is browsed). And we can click on Send to make a hit to the Dropbox API.
    #7.1 Once the hit is made from client (POSTMAN) to Dropbox API, you would see the response 200 if things are all correct. In my case, it gives me a success response as below.

#8 Now to verify the expectation, let us goto dropbox location and see if the file is uploaded via API or not. As shown in below screenshot, we can see that file is uploaded in the dropbox location successfully.

Hope you have followed the above post. So we understood how to connect to Dropbox API from POSTMAN client to store files in dropbox. Now you can guess the next step:
- If you are curious, you can try the same usecase in Pega where you create a connector in Pega to connect to Dropbox API with all the necessary request details and utlimately file from Pega should be passed and stored in dropbox.



HowToPega : All rights reserved and the contents are copyrighted to Pavan Kumar Naidu