Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Personalization


(new)

Beta

The Push Notifications API is currently available as a Private Beta product. The information contained in this document is subject to change. You acknowledge and agree that your use of the Twilio Push Notifications API is subject to the terms of the Services in Private Beta(link takes you to an external page). This means that some features are not yet implemented and others may be changed before the product is declared as Generally Available. Private Beta products are not covered by the Twilio Support Terms or Twilio Service Level Agreement.

The Push Notifications API supports Liquid(link takes you to an external page) templating for personalizing notification content. You can use variables, default values, and control flow to tailor each notification to its recipient.


Personalize notifications inline

personalize-notifications-inline page anchor

Define notification content inline and enclose each variable name in double curly braces ({{ }}). Provide a default value for every variable to ensure that the notification renders correctly when a recipient's variables object doesn't contain the corresponding key.

Pass recipient-specific values in the variables object for each entry in the to array.

1
curl -X POST 'https://comms.twilio.com/v1/PushNotifications' \
2
-H 'Content-Type: application/json' \
3
-d '{
4
"to": [
5
{
6
"token": "FCM_DEVICE_TOKEN_1",
7
"provider": "FCM",
8
"variables": {
9
"name": "Fred"
10
}
11
},
12
{
13
"token": "APN_DEVICE_TOKEN_1",
14
"provider": "APN",
15
"variables": {
16
"name": "Sonny"
17
}
18
}
19
],
20
"content": {
21
"title": "Your order update",
22
"body": "Hello {{name | default: '\''there'\''}}! Your order has shipped."
23
}
24
}' \
25
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

In this example, Fred receives "Hello Fred! Your order has shipped." and Sonny receives "Hello Sonny! Your order has shipped." If a recipient's variables object is missing the name key, the notification falls back to "Hello there! Your order has shipped."


In addition to simple variable replacement, you can use Liquid control flow structures like if and else to conditionally render parts of a notification for specific recipients.

1
curl -X POST 'https://comms.twilio.com/v1/PushNotifications' \
2
-H 'Content-Type: application/json' \
3
-d '{
4
"to": [
5
{
6
"token": "FCM_DEVICE_TOKEN_1",
7
"provider": "FCM",
8
"variables": {
9
"name": "Fred",
10
"tierName": "Gold"
11
}
12
},
13
{
14
"token": "APN_DEVICE_TOKEN_1",
15
"provider": "APN",
16
"variables": {
17
"name": "Sonny",
18
"tierName": "Silver"
19
}
20
}
21
],
22
"content": {
23
"title": "Your weekly rewards update",
24
"body": "Hi {{name | default: '\''there'\''}}! {% if tierName == '\''Gold'\'' %}As a Gold member, you'\''ve earned double points this week.{% else %}You'\''re one step away from Gold status. Keep earning!{% endif %}"
25
}
26
}' \
27
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN