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:

  1. When customer is logged in and you want fetch the coupon codes applicable for a logged in customer
  2. When customer is not logged in but you still wants to show all the coupon codes to the customer
  3. 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

  1. API Key and Secret Key for your application
  2. 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
  3. 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.

AuthorizationValue
UsernameAPI key of your application
PasswordSecret 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 nameData typeDefinitionExample
source_idstringOptional
Unique customer Id of your application
Krishna_123

Order details object (Optional)

Field nameData typeDefinitionExample
order_idstringOptional
Transaction Id from your application
rehook12345
original_price_subtotalIntMandatory
Sum of original price of all the items (MRP)
[original_price * quantity]
500
selling_price_subtotalfloat64Mandatory
Sum of selling price of all the items
[selling_price * quantity]
300
shippingfloat64Optional
shipping charge at an order level
30
statusstringOptional
Status of transaction on your application.
'pending', 'completed', 'reverted'

Item details object (Optional)

Field nameData typeDefinitionExample
product_idstringRequired
Product identification id from your application
abc_124
skustringOptional
Assigned SKU to a product from your application
124
namestringOptional
name of the product
Coke
original_pricefloat64Required
original price of the product or MRP
100
shippingfloat64Required
shipping charge at item level
30
selling_pricefloat64Required
selling price of the product
80
quantityfloat64Optional
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 namemeta data value
Key 1value 1
Key 2value 2

Example:

meta data key namemeta data value
brandRehook
categoryGrocery

📘

Meta data -limitation

  1. Meta data details are optional in the request body.
  2. 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.
  3. 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.
  4. 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 casesub caseRequest body should haveResponse body
User is signed in. Without validation on order and itemsource_id or without source_idReturns 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 inWith validation on order and item1. 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 inWithout validation on order and itemEmpty bodyReturns the all users coupon codes available for your application
User is not signed inWith validation on order and item1. 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

FieldsDefinition
coupon_codeFixed coupon code configured on Rehook
coupon_code_idCoupon Id generated against a coupon code
coupon_nameName of the coupon configured on Rehook
coupon_descriptiondescription of the coupon
coupon_terms_and_conditionsTerms and condition of the coupon. this array can have multiple values based on how many terms and conditions are added.
is_applicableIndicates if coupon code is applicable or not (values: true/false)
coupon_savings (array of objects)
order_idTransaction id of your application
messageValidation message when coupon applicability is false
source_idunique customer id of your application
statusstatus of the order as sent by your application
selling_price_subtotalSum of selling_price of all the products
total_amount[Return]

selling_price_subtotal - total_discount
total_discounttotal_discount to be given for a coupon code
total_cashbacktotal cashback to be given for a coupon code
shippingtotal shipping charge at an order as sent by you
request idAPI 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 CodeMessage
200Ok

Error Responses

If API call is failed, then Rehook will return the following HTTP success code with response body as given below:

HTTP CodeMessage
400bad request

error response body

field namedescriptionexample
CodeError code400
detailsError detailsGiven resource Id is wrong
messageerror messageResource Id not found
request_idAPI request Id assigned by Rehookabc_123

Below table shows possible list of cases with error messages

CaseError message
API Key or Secret is wrongmessage: 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 bodycoupon 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 expiredExpired coupon will not be returned in the API response
Total coupon redemption limit is exceededRehook 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 exceededRehook 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 exceededRehook 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 periodRehook 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 failedRehook 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.
Language
Authorization
Basic
base64
:
Click Try It! to start a request and see the response here!