Send a webhook action from Customer.io to a public api
A custom webhook can pass data to just about any public API on the internet. You can use it to send a text message, update a CRM or take just about any action on a customer that you’d want to do.
With a little trial and error, you should be able to connect Customer.io to another service you’re using. This guide will give you some basics to help you get started.
Creating a webhook action
In the workflow for a campaign, you can click to Add workflow item…
…and choose a webhook from the resulting modal:
After adding a Webhook, click Add Request to go into the message composer.
HTTP Request Types
Customer.io webhook actions support 4 common HTTP request types for RESTful APIs:
The one you use is dependent on what the API you’re using is expecting. Post is most likely to be used and is the default.
You can customize the headers that Customer.io sends with each request in order to support things like:
- Specifying the Content-Type
- Supporting other types of Authentication
- Setting other specific headers required for a specific API
By default, we pre-fill:
Other example “Content-Type”s are: x-www-form-urlencoded, text/plain, text/xml.
We’d recommend working with APIs using
Content-Type: application/json if possible for readability.
Headers: Basic Auth If your API requires Basic Authentication, you’ll add the username and password to the request like:
Structuring content for a webhook (JSON)
If you’re using
Content-Type: application/json, you’ll want to make sure you’re using fully formed JSON.
A good place to test this is:
A simple example for valid JSON is:
You’d create something like this by putting this text in to the editor:
Then clicking “Preview”
A slightly more advanced example is:
That will output the entire customer object in JSON format.
Structuring content for a webhook (Form encoded)
If you want to send a form encoded webhook, you’ll set the Content-type header as:
Then, the body needs to be valid form encoded text. Something like:
email@example.com&custom_attribute=value The downside of form encoded is that it’s a bit harder to structure and read since there are no line breaks and separation other than the “&” characters that join everything together.
Timeouts and Failures
We have a 4 second timeout and if we don’t get a successful (200) response in that period, or if anything but a 200 success code is returned, Customer.io will retry sending the notification several times with exponential backoff. We keep retrying up to a max of 10 times over a period of approximately 7 hours.
Testing your requests
If you’d like to test the format of your requests before pointing them at the correct API, you could se a service like Requestbin. You’d create a Bin URL on the RequestBin site and paste that in to Customer.io as the URL.
More ideas & examples
If you’re looking to see some real world examples, take a look at some of our walk throughs.