You can instantly send a personalized push notification to a specific user based on an external trigger by combining the /postEvent API method with a Customer Journey. This is ideal for transactional notifications like order status updates.
Here’s how to set it up:
1. Create a Trigger-Based Customer Journey
First, you need a Journey that will listen for your API call and send the message.
- Set the Entry Point: Create a new Customer Journey and choose Trigger-based as the entry point. Select Event as the trigger source. You can create a new event, for example,
OrderReady. - Target by UserID: In the entry element settings, ensure you are targeting users by their UserID. This allows the Journey to start for the specific user identified in your API call.
- Add a Push Message: Drag a Push Message element onto the canvas and connect it to the entry point.
Personalize the Content: In the push message editor, use Dynamic Content (Liquid templates) to insert data from the event attributes you'll be sending. Use the format
{{ event_attribute.attribute_name | default: "fallback_value" }}.For example, if you plan to send
nameanditemattributes, your message could be:Hi {{ event_attribute.name | default: "there" }}! Your {{ event_attribute.item | default: "order" }} is ready for pickup.
2. Trigger the Journey with a postEvent API Call
From your external system or backend, send a POST request to the /postEvent endpoint when you want to trigger the notification.
The request body must contain:
* application: Your Pushwoosh Application Code.
* userId: The User ID of the recipient. This must match the User ID registered in Pushwoosh.
* event: The code for the event that triggers your Journey (e.g., OrderReady).
* attributes: A JSON object containing the key-value pairs for personalization. The keys must match the attribute names used in your push message template.
Example API Request
Here is an example using cURL:
curl --request POST \
--url https://api.pushwoosh.com/json/1.3/postEvent \
--header 'Authorization: Token YOUR_API_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"request": {
"application": "XXXXX-XXXXX",
"userId": "u12345",
"event": "OrderReady",
"attributes": {
"name": "John",
"item": "Latte"
}
}
}'
When this API call is made, the Customer Journey will start for the user with userId "u12345", and they will receive a push notification that reads: "Hi John! Your Latte is ready for pickup."
Comments
0 comments
Please sign in to leave a comment.