cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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: 

get_temporary_link and could not decode input as JSON

get_temporary_link and could not decode input as JSON

jurgenatore
Explorer | Level 3

Hello.

I'm trying to get a temporary link for file with using get_temporary_link from file_properties with below listed PHP code:

$getlink_url = 'https://api.dropboxapi.com/2/files/get_temporary_link'; 

$getlink_headers = array    (   'Authorization: Bearer '. $token,
                                            'Content-Type: application/json',
                                            'data: '.
                                            json_encode(
                                                array (
                                                "path"=>"/file_storage/some_file.zip"
                                                )
                                            )

                                        );
            $ch1 = curl_init($getlink_url);
            curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch1, CURLOPT_HTTPHEADER, $getlink_headers);
            
               
            
            $response2 = curl_exec($ch1);
            curl_close($ch1);
            error_log($response2);

But i receive an error:

[php7:notice] [pid 25434] [client ::1:40512] Error in call to API function "files/get_temporary_link": request body: could not decode input as JSON, referer: http://localhost/DropTest.html

Could you please let me know what i'm doing wrong. I found solutions for other languages but not for PHP. 


Thank you in advance for support.

 

Michal

1 Accepted Solution

Accepted Solutions

Re: get_temporary_link and could not decode input as JSON

Greg-DB
Dropboxer

The /2/files/get_temporary_link endpoint is an RPC-style endpoint, so it expects the API call parameters as JSON in the request body. 

In the code you shared, you're actually sending the parameters in a header named 'data'. 

You'll need to fix your code to send them in the request body, like:

$parameters = json_encode(
                    array (
                    "path"=>"/file_storage/some_file.zip"
                    )
                );
curl_setopt($ch1, CURLOPT_POSTFIELDS, $parameters);

View solution in original post

2 Replies 2

Re: get_temporary_link and could not decode input as JSON

Greg-DB
Dropboxer

The /2/files/get_temporary_link endpoint is an RPC-style endpoint, so it expects the API call parameters as JSON in the request body. 

In the code you shared, you're actually sending the parameters in a header named 'data'. 

You'll need to fix your code to send them in the request body, like:

$parameters = json_encode(
                    array (
                    "path"=>"/file_storage/some_file.zip"
                    )
                );
curl_setopt($ch1, CURLOPT_POSTFIELDS, $parameters);

View solution in original post

Re: get_temporary_link and could not decode input as JSON

jurgenatore
Explorer | Level 3

Greg

Thank you very much for support. Now works fine:

 

$getlink_url = 'https://api.dropboxapi.com/2/files/get_temporary_link'; 

$getlink_headers = array    (   'Authorization: Bearer '. $token,
                                            'Content-Type: application/json'
                                        );
$ch1 = curl_init($getlink_url);


$parameters = json_encode(
                array (
                "path"=>"/file_storage/some_file.zip"
                )
            );
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch1, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $getlink_headers);
            
               
            
$response2 = curl_exec($ch1);
curl_close($ch1);
error_log($response2);

 

Best, Michal

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    jurgenatore Explorer | Level 3
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?