Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

Shobhit_Sharma's avatar
Shobhit_Sharma
New member | Level 2
8 years ago
Solved

Dropbox Api throwing error, "request body: could not decode input as JSON"

Whenever I use https://api.dropboxapi.com/2/sharing/get_file_metadata  with apex code or postman, I receive an error message i.e., Error in call to API function "sharing/get_file_metadata": request body: could not decode input as JSON 

My apex code is as follows:

string token = 'https://api.dropboxapi.com/2/sharing/get_file_metadata';
HttpRequest r = new HttpRequest();
r.setEndpoint(token);
r.setHeader('Authorization','Bearer ' +accesstoken);
r.setHeader('Content-Type','application/json');
r.setHeader('data','{ "file" : "id:ooT7g_X2tkAAAAAAAAAAEw" ,"actions" : [] }');
        
r.setMethod('POST');
r.setTimeout(60000);        
Http h1 = new Http();
HttpResponse res1 = h1.send(r);
string resp1 = res1.getBody();
System.debug('MetaData Status :: \n' + resp1);
  • It looks like you're sending the API parameters in a header with the name "data" in this line:

     

    r.setHeader('data','{ "file" : "id:ooT7g_X2tkAAAAAAAAAAEw" ,"actions" : [] }');
    

    The /2/sharing/get_file_metadata endpoint is an "RPC" style endpoint, so the parameters should be sent as JSON in the request body, not as a header. Update your code to send the JSON in the body instead of a header.

    I can't offer help with programming in Apex itself, but it looks like you may need to use the `setBody` method.

     

1 Reply

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    It looks like you're sending the API parameters in a header with the name "data" in this line:

     

    r.setHeader('data','{ "file" : "id:ooT7g_X2tkAAAAAAAAAAEw" ,"actions" : [] }');
    

    The /2/sharing/get_file_metadata endpoint is an "RPC" style endpoint, so the parameters should be sent as JSON in the request body, not as a header. Update your code to send the JSON in the body instead of a header.

    I can't offer help with programming in Apex itself, but it looks like you may need to use the `setBody` method.

     

About Dropbox API Support & Feedback

Node avatar for 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!