How to receive data from a Dropbox API Webhook with PHP

Have you set up a Dropbox API webhook and are having trouble receiving the data sent by Dropbox to your app?

The reason for this is likely to be the encoding of the data. Dropbox doesn’t send the data as form data as you would expect (ie application/x-www-form-urlencoded or multipart/form-data) and therefore you can’t simply fetch the data using $_POST (which is designed as a wrapper for form encoded data).

The solution is to get the raw request (minus the headers) using the following code:

$raw_data = file_get_contents('php://input');

You’ll then need to json_decode the data, as Dropbox sends your app user IDs of users with changes in a JSON format.

If you haven’t used webhooks yet – they’re great for when you have an app that is monitoring a Dropbox folder. ┬áThere is no need to constantly poll for changes, let Dropbox notify you when something is changed!

If you have any questions, or need more advice on the Dropbox API, please add a comment…

 Scroll to top