Samson
Samson

Reputation: 75

Dropbox API PHP - notification request is empty

I have what should be a very simple issue to solve, but I can't figure out what is going wrong.

Just started a project to use the new Dropbox API v2 to receive notifications for file/folder changes. Following the steps provided in the documentation provided, but I run into an issue right off the bat.

I've verified the webhook, and I do receive a POST request from Dropbox every time a file is changed, but the POST request just contains an empty array. The code is simple, as I have just begun the project:

// USED for initial verification
/*
$challenge = $_GET['challenge'];
echo $challenge;
*/

$postData = $_POST;

$post_dump = print_r($postData, TRUE);
$fpost = fopen('postTester.txt', 'w');
fwrite($fpost, $post_dump);
fclose($fpost);

$postData is an empty array with sizeOf() 0.

Any ideas?

Here is the updated code with the solution. Very simple fix.

$postData = file_get_contents("php://input");

$post_dump = print_r($postData, TRUE);
$fpost = fopen('postTester.txt', 'w');
fwrite($fpost, $post_dump);
fclose($fpost); 

Upvotes: 0

Views: 252

Answers (1)

Greg
Greg

Reputation: 16940

I believe this is because $_POST is only for application/x-www-form-urlencoded or multipart/form-data Content-Types. The payload delivered by Dropbox webhooks is application/json.

It looks like you'll instead want to use $HTTP_RAW_POST_DATA or php://input, depending on your version of PHP.

You can get the raw payload and then json_decode it to get the structured information.

Upvotes: 2

Related Questions