Inserts/Pushes any system or custom events into the rehook system. This API triggers the Rule-Engine, validates all the rules (if any) associated with the event and distributes rewards accordingly.
Rehook Platform API provides resource oriented URLs to work with your business data. Our API uses JSON for request and response. API errors are returned using standard HTTP response codes.
Introduction
Trigger event API will help you to insert/pushes any system (events defined by Rehook) or custom events (events created by your application) into Rehook system. Successful API Call will trigger the rule engine and validate all the rules associated with a given event and distribute rewards to the customer accordingly.
Your application should consume this API whenever a customer performs intended action on your application.
API details
API Endpoint: https://api.rehook.ai/events/invoke
HTTP Method: POST
Prerequisites
- API Key and Secret Key for your application
- If you don't know the API key and secret key, please go to setting module on admin panel to view API details for your application. To know more about application settings, please visit Application setting
- API key and secret key are auto generated and cannot be changed.
Authentication
You need to provide the API key and Secret of your application in every new request as Authorisation. Rehook use Basic authentication method to authenticate the API calls.
Authorization | Value |
---|---|
Username | API Key of your application |
Password | Secrete key of your application |
Parameters
Query Parameters
This API doesn't requires any query parameters. you have to provide the details in API body only.
Body Parameters - Custom events
{
"metadata": {
"Payment_mode": "UPI",
"total_amount": "250"
},
"event_name": "order_success",
"source_id": "krishna@123"
}
Body Parameters - Signup event
{
"metadata": {
"referral_code": "KBLGPN"
},
"event_name": "signup",
"source_id":"KMN@123"
}
Please refer to the below table to understand the definition of body parameters
Field name | Definition | example |
---|---|---|
event_name | required name of the event to be triggered | order_success, signup |
source_id | required Unique customer id of your application | krishna@123 |
referral_code | required valid referral code entered by the friend. referral_code is required for only signup done through referral, you can send value for referral_code field as empty for direct signup. | KBLGPN |
Meta data (optional)
You can provide the event properties in the meta data object as key value pair
meta data key name | meta data value |
---|---|
Key 1 | value 1 |
Key 2 | value 2 |
Example:
meta data key name | meta data value |
---|---|
Payment_mode | UPI |
total_amount | 250 |
Sample request body & response
Below table shows what details to be shared in the request body in a given case.
case | request body | expected outcome |
---|---|---|
New customer is signed in using a referral code | 1. Source_id (mandatory) 2. event_name (mandatory) : pass conversion event for sign up 3. metadata (optional): You may pass event properties of conversion event if required. 4. referral_code to be shared in the meta data object | 1. Rehook will assign the event against given source_id and run the rule engine to validate all the rules associated with a given event and distribute rewards to the customer accordingly 2. if source_id is not found, then rehook will create a new customer. 3. Rehook will add the referral count for the advocate |
New customer is signed in without using a referral code | 1. Source_id (mandatory) 2. event_name (mandatory) : pass conversion event for sign up3. 3. metadata (optional): You may pass event properties of conversion event if required. | 1. Rehook will assign the event against given source_id and run the rule engine to validate all the rules associated with a given event and distribute rewards to the customer accordingly 2. if source_id is not found, then rehook will create a new customer. |
Existing customer is completing an intended action on your application | 1. Source_id (mandantory) 2. event_name (mandatory) : pass intended completed action as an event (example: order_placed) 3. metadata (optional): You may pass event properties of an event if required. | 1. Rehook will save the event against given source_id 2. Rehook will trigger the rule engine to validate all the rules associated with a given event and distribute rewards to the customer accordingly. |
Request body
case 1: Action based event
{
"metadata": {
"Payment_mode": "UPI",
"total_amount": "250"
},
"event_name": "order_success",
"source_id": "krishna@123"
}
case 2: Sign up event
{
"metadata": {
"referral_code": "KMN6457"
},
"event_name": "signup",
"source_id": "krishna@123"
}
Response
{
"message": "Request processed sucessfully",
"requestId": "6df44043-ce67-914a-9242-2806afa05a86"
}
API Behaviour
- Source_id is mandatory to trigger an event
- You can pass the event properties in meta data object as key-value pair
- event_name passed in the request body can be a system event or custom event as per required by your application
- If you're triggering an event for a new customer, we suggest you to first call our create customer API to create the source id. as a fall back mechanism, however Rehook will create customer Id if source_id passed in the request body is not found on rehook dashboard.
- Successful API Call will trigger the rule engine and validate all the rules associated with a given event and distribute rewards to the customer accordingly. (Example: Customer will get 50 points on order place)
- If user is signing up using a referral code, then please send the conversion event name and referral code in the meta data object.
Success Response.
If API call is successful, then Rehook will return the following HTTP success code with response body as given above:
HTTP Code | Message |
---|---|
200 | Ok |
Error Responses
If API call is failed, then Rehook will return the following HTTP success code with response body as given below:
HTTP Code | Message |
---|---|
400 | bad request |
error response body
field name | description | example |
---|---|---|
Code | Error code | 400 |
details | Error details | Given resource Id is wrong |
message | error message | Resource Id not found |
request_id | API request Id assigned by Rehook | abc_123 |
Sample error cases
- when mandatory fields (event name or source_id) are empty in the payload.
{
"code": 401,
"key": "event_name",
"message": "event_name field is required",
"details": "event_name field is required",
"request_id": "22df9ba9-560c-99fd-a63d-44871aeb4081"
}
{
"code": 401,
"key": "source_id",
"message": "source_id field is required",
"details": "source_id field is required",
"request_id": "faf53ecf-c373-96ec-8b55-5f5602791f12"
}