FetchAllClientCoupons
Description
Fetch all coupons for a client.
Endpoint
POST /coupons/list/all
Parameters
source_id
(string): source id (optional)order
: Order details (optional)original_amount
(float64): original amount (mandatory)selling_amount
(float64): selling amount (mandatory)status
(string): status [pending, completed, reverted] (optional)shipping
(float64): shipping (optional)tax
(float64): tax (optional)payment_mode
(string): payment mode (optional)metadata
(object): metadata (optional)key1
(string): meta key 1key2
(float64): meta key 2
items
(array of object): product items (optional)original_price
(float64): original price (mandatory)selling_price
(float64): original price (mandatory)product_id
(string): product id (mandatory)sku
(string): sku (optional)name
(string): name (optional)quantity
(float64): quantity (optional)metadata
(object): metadata (optional)itemkey1
(string): meta key 1itemkey2
(float64): meta key 2
Responses
-
200 OK
-
400 Bad Request
code
(error code): NOT_FOUND_CODEmessage
(error message): Campaign not found detailsdetails
(error details): Error detailsrequest_id
(string): Request ID
Security
- Basic Authentication
Authentication
This endpoint requires Basic Authentication.
- Username:
apiKey
- Password:
apiSecret
Request Body Example
{
"source_id": "customerA_123",
"order": {
"order_id": "order_123",
"status": "pending",
"original_amount": 190,
"selling_amount": 135.97,
"shipping": 5.0,
"tax": 3.47,
"payment_mode": "UPI",
"metadata": {
"created_by": "JohnDoe",
"created_date": "2023-06-13T10:00:00",
"source": "Website"
},
"items": [
{
"product_id": "ABC123",
"sku": "SKU123",
"name": "Example Product 1",
"original_price": 190.99,
"selling_price": 149.99,
"quantity": 2,
"metadata": {
"color": "blue",
"size": "L"
}
}
]
}
}
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
Fetch coupon API will help you to fetch all the applicable coupon codes created on the Rehook dashboard. Your application can consume this API at applicable touch points on your app or web to display the coupon codes to the customers.
You can consume this API on following cases:
- When customer is logged in and you want fetch the coupon codes applicable for a logged in customer
- When customer is not logged in but you still wants to show all the coupon codes to the customer
- When customer is active on cart page to show applicable coupon codes based on cart or item validation - for Both logged in and not logged in customers.
API details
API Endpoint: https://api.rehook.ai/coupons/list/all
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 | Secret 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
{
"source_id": "101",
"order": {
"order_id": "1223456",
"status": "pending",
"original_price_subtotal": 100,
"selling_price_subtotal": 100,
"tax": 20,
"shipping": 20,
"payment_mode": "",
"metadata": {
"cart_qty": "4"
},
"items": [
{
"product_id": "123423",
"name": "product_1",
"sku": "123",
"original_price": 200,
"selling_price": 200,
"shipping": 0,
"quantity": 2,
"metadata": {
"brand": "brand_name",
"category": "grocery"
}
}
]
}
}
Parameters without an object (Optional)
Filed name | Data type | Definition | Example |
---|---|---|---|
source_id | string | Optional Unique customer Id of your application | Krishna_123 |
Order details object (Optional)
Field name | Data type | Definition | Example |
---|---|---|---|
order_id | string | Optional Transaction Id from your application | rehook12345 |
original_price_subtotal | Int | Mandatory Sum of original price of all the items (MRP) [original_price * quantity] | 500 |
selling_price_subtotal | float64 | Mandatory Sum of selling price of all the items [selling_price * quantity] | 300 |
shipping | float64 | Optional shipping charge at an order level | 30 |
status | string | Optional Status of transaction on your application. | 'pending', 'completed', 'reverted' |
Item details object (Optional)
Field name | Data type | Definition | Example |
---|---|---|---|
product_id | string | Required Product identification id from your application | abc_124 |
sku | string | Optional Assigned SKU to a product from your application | 124 |
name | string | Optional name of the product | Coke |
original_price | float64 | Required original price of the product or MRP | 100 |
shipping | float64 | Required shipping charge at item level | 30 |
selling_price | float64 | Required selling price of the product | 80 |
quantity | float64 | Optional quantity of the product in the cart | 2 |
Meta data (optional)
You can provide the meta data in order object or item object using 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 |
---|---|
brand | Rehook |
category | Grocery |
Meta data -limitation
- Meta data details are optional in the request body.
- If you want to pass any other custom fields in the API payload, then such fields can be passed as key value pairs inside metadata object.
- Our system will validate the meta data only if same meta data with key value pair with same data type is created in coupon campaign on rebook dashboard, otherwise, Rehook API will nullify the meta data provided in the request body.
- Meta data object can be passed at order or item level.
Sample request body
Below table shows what details to be shared in the request body in a given case.
Sample case | sub case | Request body should have | Response body |
---|---|---|---|
User is signed in. | Without validation on order and item | source_id or without source_id | Returns fixed coupon codes applicable for given source_id If source_id is not passed, then system returns all coupon codes applicable for your application. |
User is signed in | With validation on order and item | 1. source_id 2. order object with mandatory fields if validation to be done on order object Mandatory fields: original_price_subtotal and selling_price_subtotal, coupon_details are mandatory 3. item object with mandatory fields if validation to be done on item object Mandatory fields: original_price, selling_price, product_id, coupon_details are mandatory 4. pass both cart and item object with mandatory fields if validation to be done on both objects. | Returns validated fixed coupon codes for a given resource_id |
User is not signed in | Without validation on order and item | Empty body | Returns the all users coupon codes available for your application |
User is not signed in | With validation on order and item | 1. order object with mandatory fields if validation to be done on order object Mandatory fields: original_price, selling_price, product_id, coupon_details are mandatory 2. item object with mandatory fields if validation to be done on item object Mandatory fields: original_price, selling_price, product_id, coupon_details are mandatory 3. pass both cart and item object with mandatory fields if validation to be done on both objects. | Returns validated all users coupon codes available for your application |
Request body and response
Sample request body and API behaviour details are given below for the above mentioned cases:
Complete request payload and response:
{
"source_id": "101",
"order": {
"order_id": "1223456",
"status": "pending",
"original_price_subtotal": 100,
"selling_price_subtotal": 100,
"tax": 20,
"shipping": 20,
"payment_mode": "",
"metadata": {
"cart_qty": "4"
},
"items": [
{
"product_id": "123423",
"name": "product_1",
"sku": "123",
"original_price": 200,
"selling_price": 200,
"shipping": 0,
"quantity": 2,
"metadata": {
"brand": "brand_name",
"category": "grocery"
}
}
]
}
}
API Behaviour:
- Above payload contains the complete details of API payload.
- Order object and Item object are optional, please provide the mandatory details of order and item if you want to fetch the coupon codes based on cart and item validations.
- All other parameters in cart validations and product validations is optional.
- If you don't want to check any validations while fetching the API, then just provide the source Id in the request body to fetch the coupon code for a given customer.
- If you want to fetch the coupon code for not signed in customers without any validations, then, just consume the fetch coupon API without passing the request body, system will return all the coupon codes available for your application.
- If validation is applied on mandatory parameters and such parameters are not passed in the request body, API will return the validation error messages.
- If validation is applied on optional parameters and parameters are not passed in the request body, API will not return error, however validation error is only returned when optional parameters are passed.
- If you want to pass any other custom fields in the API payload, then such fields can be passed as key value pairs inside metadata object.
- System will return only fixed coupon codes. Bulk coupon codes to be entered by the user manually on your application and validate it using Rehook validate coupon API.
- We suggest you to pass the order and item object in all the API calls to avoid fraud coupon redemption.
Sample response for complete request body
case 1: Response body with validation is true
[
{
"coupon_code": "KMN123",
"coupon_code_id": "coupm_87QtFVPcYaLZHJ1vDaqOJ",
"coupon_name": "krishna1",
"coupon_description": "Get 50% off on grocery items",
"coupon_terms_and_conditions": [
"Terms and conditions"
],
"is_applicable": true,
"coupon_savings": {
"order": {
"order_id": "1223456",
"source_id": "KMN@123",
"status": "pending",
"original_price_subtotal": 400,
"selling_price_subtotal": 400,
"total_discount": 100,
"total_amount": 300,
"total_cashback": 0,
"shipping": 20,
"coupon_details": {},
"metadata": {
"cart_qty": "4"
},
"items": [
{
"metadata": {
"brand": "brand_name",
"category": "grocery"
},
"name": "product_1",
"original_price": 200,
"product_id": "123423",
"quantity": 2,
"selling_price": 200,
"sku": "123"
}
]
}
},
"request_id": "6a1c4781-3e33-9e9e-953e-fc2d3fd38411"
}
case 2: response body when validation is false
[
{
"coupon_code": "KMN123",
"coupon_code_id": "coupm_87QtFVPcYaLZHJ1vDaqOJ",
"coupon_name": "krishna1",
"coupon_description": "Get 40% off on whole cart",
"coupon_terms_and_conditions": [
"Terms and conditions"
],
"is_applicable": false,
"message": "coupon is not available at this moment or expired",
"coupon_savings": {
"order": {
"order_id": "1223456",
"source_id": "KMN@123",
"status": "pending",
"original_price_subtotal": 400,
"selling_price_subtotal": 400,
"total_discount": 100,
"total_amount": 300,
"total_cashback": 0,
"shipping": 20,
"coupon_details": {},
"metadata": {
"cart_qty": "4"
},
"items": [
{
"metadata": {
"brand": "brand_name",
"category": "grocery"
},
"name": "product_1",
"original_price": 200,
"product_id": "123423",
"quantity": 2,
"selling_price": 200,
"sku": "123"
}
]
}
},
"request_id": "6a1c4781-3e33-9e9e-953e-fc2d3fd38411"
}
sample response fields and definition
Fields | Definition |
---|---|
coupon_code | Fixed coupon code configured on Rehook |
coupon_code_id | Coupon Id generated against a coupon code |
coupon_name | Name of the coupon configured on Rehook |
coupon_description | description of the coupon |
coupon_terms_and_conditions | Terms and condition of the coupon. this array can have multiple values based on how many terms and conditions are added. |
is_applicable | Indicates if coupon code is applicable or not (values: true/false) |
coupon_savings (array of objects) | |
order_id | Transaction id of your application |
message | Validation message when coupon applicability is false |
source_id | unique customer id of your application |
status | status of the order as sent by your application |
selling_price_subtotal | Sum of selling_price of all the products |
total_amount | [Return] selling_price_subtotal - total_discount |
total_discount | total_discount to be given for a coupon code |
total_cashback | total cashback to be given for a coupon code |
shipping | total shipping charge at an order as sent by you |
request id | API request id generated by Rehook for your request |
Request body when customer is logged in
case 1: Without any validations
Request body:
{
"source_id": "101"
}
API Behaviour:
- If you want to fetch all the coupon codes applicable for a logged in customer without any validation on cart or item, you just need to provide the source_id in the API request body.
- For above payload, Rehook API will return all the active coupon codes available for source_id.
- Returned coupon codes will be the coupon codes distributed to only assigned users.
case 2: With cart or item validations
{
"source_id": "101",
"order": {
"order_id": "1223456",
"status": "pending",
"original_price_subtotal": 100,
"selling_price_subtotal": 100,
"tax":20,
"shipping":20,
"payment_mode": "",
"metadata": {
"cart_qty":"4"
},
"items": [{
"product_id": "123423",
"name":"product_1",
"sku":"123",
"original_price": 200,
"selling_price": 200,
"shipping":0,
"quantity":2,
"metadata": {
"brand": "brand_name",
"category":"grocery"
}
}
]
}
}
API Behaviour:
- If you want to fetch all the coupon codes applicable for a logged in user with validation on cart or item level, you have to pass the source_id and order or item object details.
- With reference to above payload, Rehook API will return the applicable fixed coupon codes for source_id = 101 and cart validation added on the coupon code matches with order details passed in the request body.
For not signed in customers
Case 1: without any validations
EMPTY BODY
API Behaviour:
- If you want to fetch the coupon codes for a not signed customers, consume the fetch coupon API with empty request body.
- In this case, Rehook API will return all coupon codes available for your applications without checking any validations on customer/order/Item.
- List of coupon codes returned will be the coupon codes distributed assigned users and All users as Rehook cannot validate the coupon code applicability on resource_id
Case 2: with order/item validations
"order": {
"order_id": "1223456",
"status": "pending",
"original_price_subtotal": 100,
"selling_price_subtotal": 100,
"tax":20,
"shipping":20,
"payment_mode": "",
"metadata": {
"cart_qty":"4"
},
"items": [{
"product_id": "123423",
"name":"product_1",
"sku":"123",
"original_price": 200,
"selling_price": 200,
"shipping":0,
"quantity":2,
"metadata": {
"brand": "brand_name",
"category":"grocery"
}
}
]
API Behaviour:
- If you want to fetch the coupon codes for a not signed customers with cart or item validation while customer is active on your cart page, consume the fetch coupon API without passing the resource id and passing the cart or item object with mandatory fields.
- With reference to above payload, Rehook will return all the coupon codes matching the order object and item object validations.
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 |
Below table shows possible list of cases with error messages
Case | Error message |
---|---|
API Key or Secret is wrong | message: unauthorized error details: appId or app secret invalid |
Wrong field is added in the request body or mandatory fields are not passed in the request body | coupon applicability will be false. system will send the error message in the each coupon code object. message: "invalid payload, original_price_subtotal and selling_price_subtotal is required and should not be 0", |
Coupon is expired | Expired coupon will not be returned in the API response |
Total coupon redemption limit is exceeded | Rehook will return the coupon code with applicability as 'false' with message 'coupon code redemption total_limit exceeded' in the response body. |
Per user redemption is exceeded | Rehook will return the coupon code with applicability as 'false' with message 'coupon code redemption per_user_limit exceeded' in the response body. |
Daily/monthly/weekly redemption is exceeded but total or per user redemption is not exceeded | Rehook will return the coupon code with applicability as 'false' with message 'coupon code redemption per_day/month/week_limit exceeded' in the response body. |
Coupon is not available for specific days or time within coupon time period | Rehook will return the coupon code with applicability as 'false' with message 'coupon is not available at this moment or expired' in the response body. |
Coupon validation is failed | Rehook will return the coupon code with applicability as 'false' with validation message 'selling_price_subtotal should be greater than 200.00' in the response body. |