parse.com - Could not access Dropbox API via parse cloud code although works with CURL -


i trying access following end-point parse cloud code:

https://api.dropboxapi.com/2/users/get_current_account 

details of end-point:

https://www.dropbox.com/developers/documentation/http/documentation#users-get_current_account

my cloud function @ point of making request.

return parse.cloud.httprequest({   method: 'post',   url: 'https://api.dropboxapi.com/2/users/get_current_account',   headers: {     'authorization': 'bearer ' + accesstoken   } }); 

error received dropbox:

error in call api function "users/get_current_account": bad http "content-type" header: "application/x-www-form-urlencoded".  expecting 1 of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack" 

i tried using curl:

curl -x post https://api.dropboxapi.com/2/users/get_current_account --header "authorization: bearer **access_token" 

this worked , got user's data.

based on error, modified cloud code:

return parse.cloud.httprequest({   method: 'post',   url: 'https://api.dropboxapi.com/2/users/get_current_account',   headers: {     'content-type': 'application/json',     'authorization': 'bearer ' + newaccesstoken   } }); 

now got following error:

error in call api function \"users/get_current_account\": request body: not decode input json 

there no request body in httprequest. tried setting body null , ''. both gave same error.

first, don't understand why dropbox api requires post request no parameters.

second, how resolve error.

many thanks!

----- update -----

have tried other 2 content types error i.e.

'content-type': 'application/json;charset=utf-8' 'content-type': 'text/plain; charset=dropbox-cors-hack' 

and still same error:

error in call api function \"users/get_current_account\": request body: not decode input json 

finally! worked me:

return parse.cloud.httprequest({   method: 'post',   url: 'https://api.dropboxapi.com/2/users/get_current_account',   headers: {     'content-type': 'application/json; charset=utf-8',     'authorization': 'bearer ' + newaccesstoken   },   body: json.stringify(null) }); 

i had use json.stringify(null) in body.

the link below helped me in identifying solution:

https://www.dropboxforum.com/hc/en-us/community/posts/204379696-get-current-account-api-is-strange-and-does-not-work-with-common-sense-


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -