Samson Samson - 1 year ago 106
PHP Question

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);

is an empty array with

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);

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download