cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to Retrieve a new short-lived access token through Javascript

Unable to Retrieve a new short-lived access token through Javascript

sr_c
Explorer | Level 3
Go to solution

Hello,

I followed the approach described in below post to get refresh token

https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Get-refresh-token-from-access-token/td-...

 

Through Javascript I am trying to get new short lived access token (step 7 in above post) using below code, but I am getting error as given below

-->"error": "invalid_request", "error_description": "The request parameters do not match any of the supported authorization flows. Please refer to the API documentation for the correct parameters."

 

If I tried the same through Postman I am able to get the access token.

 

My javascript code is given below

--------------------------------------------------------

let tokobj = {
"refresh_token" : <My refresh token obtained using above approach>,
"grant_type" : "refresh_token",
"client_id" : <my app key>,
"client_secret" : <my app secret>
}
let reftokendpoint = "https://api.dropbox.com/oauth2/token";
let tokenOptions = {
method: "POST",
headers: {
"Content-Type" : "application/json"
},
body: JSON.stringify(tokobj)
}

const tokenResults = await fetch(reftokendpoint, tokenOptions);
const tokenPost = await tokenResults.text();
console.log('Exec status', tokenPost)

------------------------------------------------------------------------------------

 

Please suggest how this can be resolved

 

Thanks

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

That would change the "Content-Type" request header value that you send, but you need to also make sure the value you're sending in the body actually uses that format. That is, you should be formatting the parameters accordingly, not using JSON.stringify. For example, you may want to use URLSearchParams, or whatever functionality you prefer and have available for formatting the parameters accordingly.

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

The parameters for the /oauth2/token endpoint should be sent as 'application/x-www-form-urlencoded' POST parameters, not JSON. I see your code is sending them as JSON so the API does not receive them and so the operation fails with that error. Please update your code to send the parameters using the  'application/x-www-form-urlencoded' format.

sr_c
Explorer | Level 3
Go to solution

Hello @Greg-DB

I tried with below, but the error remains same. Not sure where is the issue.

headers: {
"Content-Type" : "application/x-www-form-urlencoded"
}
Thanks

Greg-DB
Dropbox Staff
Go to solution

That would change the "Content-Type" request header value that you send, but you need to also make sure the value you're sending in the body actually uses that format. That is, you should be formatting the parameters accordingly, not using JSON.stringify. For example, you may want to use URLSearchParams, or whatever functionality you prefer and have available for formatting the parameters accordingly.

sr_c
Explorer | Level 3
Go to solution

Hi @Greg-DB 

Thanks a lot. It solved my issue

 

Thanks

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    sr_c Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?