Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
rubbermeetsrd
4 years agoExplorer | Level 3
Javascript responseError in call to API function "files/move:2"
I'm working on a google app script to move a pdf file from one folder in Dropbox to another. I have it working in Postman but am having trouble getting it to work in my google app script. I am getting the following error: 'responseError in call to API function "files/move:2": request body: could not decode input as JSON'
I don't know if it has anything to do with the fact that the API body is supposed to be 'raw' format. I am not familiar with this format.
function moveDocWithinDB(dropboxAccessToken,ctrData){
Logger.log("Function moveDriverDoc ");
var raw = {
"from_path":"/Driver Shared Files/Anna/Andrew Walter- RMR Shared/(Paperwork)/TEST1234568_POD.pdf",
"to_path":"/Customer Delivery Orders/Active DO's/ABC Corp/TEST1234568_POD.pdf",
"allow_shared_folder": false,
"autorename": false,
"allow_ownership_transfer": false
}
var headers= {
"Content-Type": "application/json",
"Authorization": "Bearer "+ dropboxAccessToken,
}
var options = {
method: 'POST',
headers: headers,
data: raw,
muteHttpExceptions: true,
};
var response = UrlFetchApp.fetch(apiUrl, options);
Logger.log("response" + response)
}
5 Replies
- Здравко4 years agoLegendary | Level 20
rubbermeetsrd wrote:... I am getting the following error: 'responseError in call to API function "files/move:2": request body: could not decode input as JSON'
var headers= {"Content-Type": "application/json", <<<<<<"Authorization": "Bearer "+ dropboxAccessToken,}var options = {method: 'POST',headers: headers,data: raw, <<<<<<<<<<<<muteHttpExceptions: true,};var response = UrlFetchApp.fetch(apiUrl, options);...
Hi rubbermeetsrd,
🙂 What are you expecting? You correctly declared "application/json" format, but by default how fetch is formatting the passed map? 🤔 Isn't it a form encoding? 😉
Hope this gives direction.
- rubbermeetsrd4 years agoExplorer | Level 3
What am I expecting? I am expecting the pdf file to move from one folder to another which it does in Postman.
In Postman, the body format is raw. I am not familiar enough with fetch calls to say whether they are encoded forms or not. This is the API call working in Postman (access token is whited out). When I brought up the move_v2 api call, the template was set up as a raw body which worked.
- Здравко4 years agoLegendary | Level 20
rubbermeetsrd wrote:... When I brought up the move_v2 api call, the template was set up as a raw body which worked.
...
I don't know what you mean 'raw body', but your 'template' seems correct. It should work. Why are you NOT calling 'move_v2' in the same way? 🤷 Take a look on your OP. Is it the same or not exactly? 🙂
- Greg-DB4 years ago
Dropbox Community Moderator
rubbermeetsrd The /2/files/move_v2 endpoint is an "RPC" style endpoint, meaning it expects the parameters as JSON in the request body. The "request body: could not decode input as JSON'" error you're getting indicates that the request body did not contain valid JSON, and so the Dropbox API was unable to understand it.
You'll need to debug your code to make sure you're sending valid JSON in the request body. As Здравко noted, make sure you check which code you're running, as the code in your screenshot does not match the code in your original post. Specifically, one does convert the parameters to JSON using JSON.stringify, and one does not.
- rubbermeetsrd4 years agoExplorer | Level 3
I apologize if I confused my post by showing testing within postman. Ultimately, I was working to get a google app script to move a dropbox file from one folder to another. Everyone was correct, there was an issue with the response body. Given that I couldn't find an example of a google script that made this dropbox api call I was at a loss at to my issue. After much trial and error, I got it working. Here is the solution:
I changed data to payload and it worked. This was not obvious in the Dropbox api documentation. Hope this helps someone else in the future.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!