Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook sends empty POST to a webhook

I am trying to install a webhook for leadgen event for my page via a facebook app. So I have:

  1. Facebook Page where leads come from
  2. Facebook App
  3. Webserver where I want to save leads

App and webserver are connected well I believe. Webhook is shown at app page etc. But when I am trying to create a test lead with this tool https://developers.facebook.com/tools/lead-ads-testing I am getting a POST request with no data in it.

I was suspecting permissions problems, but I am able to check a lead from page (via leadgen_id) directly with PHP SDK and the POST request is sent from Facebook just by URL, so they don't know about tokens yet.

UPD Plain POST request to the same url (curl -d "param=value" https://..url..) works as expected.

like image 344
leitasat Avatar asked Mar 10 '16 12:03

leitasat


People also ask

Does Facebook use Webhooks?

Webhooks allows you to receive real-time HTTP notifications of changes to specific objects in the Facebook Social Graph. For example, we could send you a notification when any of your app Users change their email address or whenever they comment on your Facebook Page.

What is a payload in Webhook?

Webhook payloads contain the installation property when the event is configured for and sent to a GitHub App. For more information, see "Building GitHub App." The unique properties for a webhook event are the same properties you'll find in the payload property when using the Events API. One exception is the push event.


2 Answers

Facebook sends webhook data as Content-Type: application/json, not as …: application/x-www-form-urlencoded (as a normal form with method=post would.)

Therefor, PHP does not populate $_POST – you need to read the raw input stream instead. That can be done using file_get_contents('php://input') – and then just apply json_decode on that data, and you’ll have a proper data structure to work with.

like image 190
CBroe Avatar answered Oct 13 '22 13:10

CBroe


Facebook sends the leads data in the request body. If you are using a framework, please check if you have access to the request body. Try using a third party intermediate service like Runscope to see the full request, it is very usef

like image 23
Saiyed Zaidi Avatar answered Oct 13 '22 13:10

Saiyed Zaidi