The Webhooks - Receive a web request with a JSON payload trigger allows you to set up Applets that take the JSON body from a web request and put it in a single ingredient {{JsonPayload}}
.
You can parse the JSON with filter code to build conditions based on the data or split it up into individual action fields.
As an example, let's send a web request with the following body:
curl -X POST -H "Content-Type: application/json" -d \
'{
"user": {
"name": "Ben",
"email": "ben@example.com",
"status": "Platinum",
"customer_since": "6/10/2013"
}
}' \
https://maker.ifttt.com/trigger/new_customer/json/with/key/my_secret_key
Our goal is to populate individual cells in a Google Sheet with the name, email, etc. using the Google Sheets - Add row to spreadsheet action.
However, if we simply set the Formatted row field to {{JsonPayload}}
, all data will be added to a single cell in the spreadsheet.
Instead, we can parse the JSON with the JSON.parse
method, adding each value to a separate cell with the following filter code:
let payload = JSON.parse(MakerWebhooks.jsonEvent.JsonPayload)
let formattedRow = `${payload.user.name}|||${payload.user.email}|||${payload.user.status}|||${payload.user.customer_since}`
GoogleSheets.appendToGoogleSpreadsheet.setFormattedRow(formattedRow)
Each JSON body is unique and can have many different keys, values, or even arrays, so you'll need to modify this code depending on the structure of your web request's JSON body.
The {{JsonPayload}} ingredient is (none)
Note that the URL for the Webhooks - Receive a web request with a JSON payload trigger is in a slightly different format than the regular IFTTT Webhook URL (https://maker.ifttt.com/trigger/{event}/with/key/{key}
vs https://maker.ifttt.com/trigger/{event}/json/with/key/{key}
).
If the URL of your web request does not include /json/
as above, the {{JsonPayload}}
ingredient will be empty: