Testing webhooks

I'm having a bit of trouble testing a webhook.  They are registering OK: I can use the list webhooks api to see them fine. (I'm using php wrapper...)

When I call the test api (just in a browser), I get a 200 OK, and my script receiving them at the moment just emails me the POST data... of which there is none.  It's just an empty array.

My list is empty at the moment - but I don't think it's made any difference whether there's some members or not.

Any clues?  What am I missing?



jamesm, 6 years ago

Hi Matt,

The data returned by the webhooks 'test' route won't have any values from your list, so you're correct: no need for real subscribers.

You can check that your webhooks are configured the way you want by temporarily pointing them at postbin.org, which records all POST data sent to a given route.  Once you've captured some data, you could use that to test that your email-POST script is interpreting it correctly.

If you don't have any luck with that, perhaps paste us the relevant bits of your code so we can see what's going wrong.


tobyb tobyb, 6 years ago

Hi Matt,

As a point of reference, we've included sample code for receiving webhook notifications in the PHP wrapper. Since the webhook data is not a normal form POST, the $_POST superglobal is not populated by the PHP environment prior to script execution.

MattParker, 6 years ago

Hi Toby and James


I'm using Zend Framework, and you're right, $request->getPost() (and $_POST) were empty.  However, $request->getRawBody() contains the data.

I'm a bit puzzled as to why this should be, though.  I wouldn't have expected a form to have anything to do with it: a POST from a browser is just a list of fieldnames and values, after all - whether they've come from a form, a javascript ajaxey style POST, or someone monkeying around and doing it manually. 


MattParker, 6 years ago

By the way, I think there's a typo in the webhook docs.  On the subscriber de-activate bit, the sample request has Type: "Subscribe" but I think it should be Type: "Deactivate"


MattParker, 6 years ago

Some more:

it doesn't appear that there's anyway to tell the source of a webhook from the data being passed.  This means that if my API call adds a subscriber, I get a 'Subscribe' POST message right back but have no easy way to detect the circularity.  This adds considerably to the complexity of my implementation, but a 'Source' parameter in the POSTed data which related to the triggers in the API docs (i.e. 'Form' | 'Api' | 'FileImport' etc) would make it really easy.  SignupIPAddress is almost there, but it seems only to come in manual updates that I make through createsend.  The parameter's missing completely when I do API subscriptions.  And it only appears to come on Subscribe hooks, not the others.

Any chance you could look to add this?  Without it I'm not sure webhooks can work, really, it just feels all too fragile.



bc173, 4 years ago

+1 for Matt's request in adding a source.

Even better, it should post some kind of secret token, otherwise this is an open gate for hackers!

It concerns me that the $_POST variable is empty... Should this be stated in the docs? Or is this PHP only issue?

terryt terryt, 4 years ago

Hi bc173,

I've added your vote for adding a source to the webhook calls.

As for $_POST not being filled in, this is to be expected. $_POST handles form data in the format of <key>=<value>&<key>=<value>&... in the body of the request. However, as described on http://www.campaignmonitor.com/api/webhooks/#whats_a_webhook we actually don't send data this way. Instead, we send the data to you using JSON, which would be very hard for $_POST to handle appropriately.

Hopefully this clears some questions up that you have, but let me know if anything is still unclear.

Terry Tice

Terry Tice
Campaign Monitor

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free