Workflows ‐ How to create - kangaroorewards/api-docs GitHub Wiki
Creating a Workflow with Kangaroo Rewards API
Creating a workflow with Kangaroo Rewards API involves several steps. This tutorial will guide you through the process step-by-step.
Objective: Learn how to create a workflow using the Kangaroo Rewards API, from registering an app to making authenticated API calls.
Prerequisites:
- Basic understanding of APIs and HTTP requests.
- A registered business account with Kangaroo Rewards.
- An API client like Postman or cURL installed.
- An OAuth2 App registered with Kangaroo Rewards
- A valid Access Token
Creating a Workflow
1. Authentication
Get an access token or refresh an existing one as explained here. With the access token, you can start making API calls.
2. Make a request to the API endpoint using cURL
curl -X POST https://api.kangaroorewards.com/workflows \
-H "Authorization: Bearer <access_token>" \
-H "X-Application-Key: <X-Application-Key>" \
-H "Accept: application/vnd.kangaroorewards.api.v1+json" \
-H "Content-Type: application/json" \
-d '{
"name": "My Workflow",
"published_at": "2024-01-01 08:00:00",
"expires_at": "2028-12-31 23:00:00",
"targeted_flag": 0,
"triggers": [
{
"main_trigger_id": 1
}
],
"actions": [
{
"main_action_id": 1,
"temp_id": 2,
"temp_parent_id": 1,
"relations": {
"entity_id": 12345,
"entity_type": "Template",
"value": "",
"label": "Send Email"
}
}
]
}'
This is a simple workflow with one trigger and one action.
Note: Replace
<access_token>
with the actual access token. This request creates a new workflow that sends an email when a specific event occurs. Replaceentity_id
with the actual ID of the email template you want to use.
Workflow Actions:
When adding an action to the workflow, it is necessary to generate a unique temporary ID and assign the parent ID for that action. The temporary ID could be an auto-incremented number unique to that workflow. The initial action will possess temp_id = 1
and parent = null
, with subsequent actions incrementing the temp_id
by 1 and assigning the parent ID accordingly (e.g., temp_id = 2
, parent = 1
for the second action, and so forth).
3. Handle the response appropriately in your code.
Conclusion
Congratulations! You've successfully created a workflow with the Kangaroo Rewards API. This tutorial covered:
- Registering an app and obtaining credentials.
- Implementing OAuth 2.0 authentication.
- Creating a workflow via the API.
Additional Resources
- Official Documentation: Kangaroo Rewards API Documentation
- Community Support: Kangaroo Rewards Knowledge Base
- Workflows API Reference: Workflows API Reference
Feel free to reach out to support if you have any questions or need further assistance.
Examples
Example of a delay type action:
{
"actions": [
{
"main_action_id": 4,
"temp_parent_id": 1,
"temp_id": 2,
"relations": [
{
"entity_type": "Wait",
"value": 86400 // seconds
}
]
}
]
}
This example defines a workflow action that introduces a 24-hour delay before continuing to the next step. The action might be dependent on another action (based on temp_parent_id
) and has unique identifiers within the workflow creation process (main_action_id
and temp_id
).
Inside the "actions" array, there's a single object representing one action.
main_action_id
: This property holds the action type identifier for a specific action within the workflow. Its value is 4 in this example.temp_parent_id
: This property indicates the relationship between actions. The value 1 suggests this action is dependent on another action with ID 1.temp_id
: This is a temporary identifier used during workflow creation. Its value is 2 here.relations
: This key holds an array containing details about the action itself.
Within the "relations" array, there's a single object defining the action type
entity_type
: This property specifies the type of action. Here, the value is "Wait", indicating this is a delay action.value
: This property holds the value for the delay. The value is 86400, which is the number of seconds in 24 hours. This means the workflow will be paused for one day (24 hours) before proceeding to the next action.