cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

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

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

deebee_it
Helpful | Level 5
Go to solution

Good morning,
I do this request with Arduino:

  client.print(String("POST /2/files/list_folder HTTP/1.1\r\n") +
               "Host: api.dropboxapi.com" +
               "User-Agent: ESP8266/Arduino_YAGI\r\n" +
               "Authorization: Bearer " + (String)my_token +"\r\n" +
               "Accept: */*"+
               "Content-Type: application/json" +
               "Content-Length: 33" + "\r\n" + "\r\n" +
               "Dropbox-API-Arg: {\"path\":\"/glucose/201901/09/15/\"}"
               ); 

so, the arg is:

               Dropbox-API-Arg: {"path":"/glucose/201901/09/15/"}

The 'client' variable is:

               WiFiClientSecure client;

where 'WiFiClientSecure' is a package of the library to do secure calls.

But I receive this error:

HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 10 Jan 2019 09:53:23 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Content-Security-Policy: sandbox; frame-ancestors 'none'
X-Dropbox-Request-Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Content-Disposition: attachment; filename='error'

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

Any idea to resolve this error? 

Thank you very much in advance!

1 Accepted Solution

Accepted Solutions

deebee_it
Helpful | Level 5
Go to solution

FOUND!
I used static IP:

162.125.5.7 

to access the server.

 

Probably Drobbox changed the IP a few days ago.

Now I switched to 

api.dropboxapi.com
and everything works like a charm.
 
Thank you for the support! 🙂

View solution in original post

11 Replies 11

Greg-DB
Dropbox Staff
Go to solution

The /2/files/list_folder endpoint is an "RPC"-style endpoint, meaning it expects the parameters in the request body (not in a request header). 

Please move your parameters to the request body instead of the "Dropbox-API-Arg" header and try again. (The "Dropbox-API-Arg" header is only used for content-upload and content-download -style endpoints.)

deebee_it
Helpful | Level 5
Go to solution

Good morning. 

I go right with this call for about 1 year:

 

 
  request = String("POST /2/files/list_folder HTTP/1.1") + "\r\n"
                + "Host: api.dropboxapi.com" + "\r\n"
                + "User-Agent: ESP8266/Arduino_blabla"\r\n"
                + "Authorization: Bearer MYTOKENxxxxx\r\n"
                + "Accept: */*" + "\r\n"
                + "Content-Type: application/json; charset=utf-8" + "\r\n"
                + "Content-Length: " + request_data.length() + "\r\n\r\n"
                + request_data
                ;
 
With this request_data:
request_data = "{\"path\":\"" + MYPATH+ "\"}";
Now, days ago I started getting this error:
Error (4xx)We can't find the page you're looking for.
So, probably some logic is changed serverside...
May you please tell me what do I need to change in my API call?
Thank you.
 

Здравко
Legendary | Level 20
Go to solution

Hi @deebee_it,

You haven't mentioned what is the exact "MYPATH".

First: Are you sure the path, you are referring to, exists?

Second: You are relying on utf-8 encoding. Take in mind that Dropbox interpret all JSON input as a ASCII string, the encoding set is ignored! If you are using some simbol(s) outside ASCII set, make sure they are JSON-encoded (\uXXXX, where XXXX is hexdecimal unicode code point).

 

PS: By the way, you have put in your expression too many, meaningless string additions. Better do some of them join to each other (for example: "Host: api.dropboxapi.com" + "\r\n" could become "Host: api.dropboxapi.com\r\n") and remove the pluses between literals string on different lines (they gonna concatente to each other at compile time). Use pluses only where needed. 😉 In such a way lot of resources gonna be saved and the application speeds up.

Greg-DB
Dropbox Staff
Go to solution

@deebee_it Based on the output you shared, it seems like the Dropbox servers weren't able to recognize your HTTP request as a valid API call. As Здравко said, it may be helpful to know what your 'MYPATH' value is. Can you print out the entire HTTP request (redacting the access token) so we can see what may not be formatted correctly?

deebee_it
Helpful | Level 5
Go to solution

Here is:

 

POST /2/files/list_folder HTTP/1.1
Host: api.dropboxapi.com
User-Agent: ESP8266-Arduino_blabla
Authorization: Bearer xxxxx
Content-Type: application/json; charset=utf-8
Content-Length: 33

{"path":"/glucose/202011/10/09/"}

 

Здравко
Legendary | Level 20
Go to solution

Seems http format is acceptable, but what about path existence? For example, you can check the root folder list results on Dropbox API Explorer with empty path and the same access token used here. Does the "glucose" folder appear in the result? 🤔 If Yes, continue the check recursively.

deebee_it
Helpful | Level 5
Go to solution

The path exists: I looked directly in my account and I access it with no problem using a js web page!

I tried editing the token in my Arduino call, using a random dummy token... And the error is the same: 4xx... not found...

I thought that the error should be different, or not? 😐

deebee_it
Helpful | Level 5
Go to solution

Here is the request header of the js web page (that works well OK):

POST /2/files/list_folder HTTP/2
Host: api.dropboxapi.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0
Accept: */*
Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Authorization: Bearer xxxxxxxx
Content-Type: application/json
Content-Length: 33
Origin: https://xxxx
Connection: keep-alive
Referer: https://xxxx
TE: Trailers

And the request:

{"path":"/glucose/202011/10/09/"}

Здравко
Legendary | Level 20
Go to solution

Did you check what I have advised above or not? Notice different token could have different access on same account!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    deebee_it Helpful | Level 5
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?