Curious about A, B, C, and D drives? Learn what they mean and how to use them effectively with Dropbox in this handy guide! - check it out now!

Forum Discussion

autratec's avatar
autratec
Helpful | Level 6
5 years ago
Solved

Error in call to API function "files/list_folder": request body: could not decode input as JSON

Looks like this question being raised before. i did try postman and able to pass the API message to box api and return sucessfully.

 

i am integrate MT4/MQL4 language with Dropbox. The code is like this:

 

int res;
string signal,out_header,in_header,URL,in_signal;
char body[],result[];

URL = "https://api.dropboxapi.com/2/files/list_folder";
out_header = "Authorization: Bearer ,<token>\r\nContent-Type: application/json";
signal = "{\"path\": \"/Home\"}" ;

StringToCharArray (signal,body,0,-1,CP_ACP);
res = WebRequest("POST",URL,out_header,0,body,result,in_header);
in_signal = CharArrayToString(result,0,-1,CP_ACP);

 

I do include "{\"path\": \"/Home\"}" in the body and tried couple times and still facing the error: Error in call to API function "files/list_folder": request body: could not decode input as JSON

 

Plesae suggest what might be wrong.

 

thx.

  • autratec's avatar
    autratec
    5 years ago

    Здравко 

     

    Hi, thanks for the advice. the second suggestion works:

    ArrayResize(body,ArraySize(body)-1);

    thank you again. 

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    Hi autratec,

    The only secure way to investigate what's going on would be take a look on the raw http stream and see what's the problem there. As far as I can see, there are 2 possible trouble points. In 'out_header' you miss the trailing separator, so header block and the request body could stick together. Add '\r\n' at the end! Next, your 'body' contains not only the actual body, but the string termination symbol at the end, also. I'm not sure, but the server could get confused because of. Strip it using something like:

    ArrayResize(body,ArraySize(body)-1);

    just before call to WebRequest.

    Hope this gives the right direction.

    • autratec's avatar
      autratec
      Helpful | Level 6

      Здравко 

       

      Hi, thanks for the advice. the second suggestion works:

      ArrayResize(body,ArraySize(body)-1);

      thank you again.