Skip to main content

Loyalty Challenges API

The Loyalty Challenges API allows you to manage loyalty programs and challenges in the Nilo platform. Loyalty challenges reward customers with points when they purchase specific products and reach a required amount.

Understanding Loyalty Challenges

Loyalty Challenges in Nilo are gamified promotions that reward customers:

  • Challenge Structure
    • Unique internal code for identification
    • Title and description for display
    • Points given as reward
    • Required purchase amount to achieve the challenge
    • Validity period (start and end dates)
    • List of products that qualify for the challenge

Important Considerations

  1. Unique Codes: Each challenge requires a unique internal code (same as in your ERP)
  2. Points System: Define how many points customers earn when completing the challenge
  3. Required Amount: Set the minimum purchase amount needed to complete the challenge
  4. Product Scope: Specify which products count towards the challenge
  5. Date Validity: Challenges are only active within the start and end dates

Single Challenge Operations

Get Loyalty Challenge Details

GET/loyaltychallenge/{code}

Retrieve detailed information about a specific loyalty challenge.

Path Parameters

ParameterTypeRequiredDescription
codestringYesInternal code of the loyalty challenge

Response Example

{
"id": 1,
"title": "Summer Points Challenge",
"description": "Earn points on summer products",
"image": "https://example.com/challenge.jpg",
"internalCode": "CHALLENGE-001",
"pointsGiven": 100,
"requiredMoney": 500,
"enabled": true,
"startDate": "2025-06-01",
"endDate": "2025-08-31",
"products": [
{
"internalCode": "PROD-001"
},
{
"internalCode": "PROD-002"
}
]
}

Example Usage

const headers = {
Authorization: "YOUR_AUTH_TOKEN",
"x-api-key": "YOUR_API_KEY",
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/loyaltychallenge/CHALLENGE-001",
{
method: "GET",
headers: headers,
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

List All Loyalty Challenges

GET/loyaltychallenge

Retrieve a list of all loyalty challenges with pagination and filtering support.

Query Parameters

ParameterTypeRequiredDescription
takenumberNoNumber of items per page (default: 50, max: 50)
pagestringNoPage number (default: 1)
cursorstringNoCursor for pagination. First call should pass 0, subsequent calls use the cursor from the previous response
enabledbooleanNoFilter by enabled status
fromstringNoStart date filter (YYYY-MM-DD)
tostringNoEnd date filter (YYYY-MM-DD)

Create or Update Loyalty Challenge

PUT/loyaltychallenge

Create a new loyalty challenge or update an existing one.

Request Body Parameters

ParameterTypeRequiredDescription
titlestringYesTitle of the challenge
internalCodestringYesUnique identifier for the challenge
descriptionstringNoDescription of the challenge
imagestringNoURL of the challenge image
pointsGivennumberYesPoints awarded when challenge is completed
requiredAmountnumberYesMinimum purchase amount to complete challenge
startstringYesStart date (YYYY-MM-DD)
endstringYesEnd date (YYYY-MM-DD)
enabledbooleanYesWhether the challenge is active
productsarrayYesArray of products that qualify for the challenge

Request Body Example

{
"title": "Summer Points Challenge",
"internalCode": "CHALLENGE-001",
"description": "Earn 100 points when you spend $500 on summer products",
"image": "https://example.com/challenge.jpg",
"pointsGiven": 100,
"requiredAmount": 500,
"start": "2025-06-01",
"end": "2025-08-31",
"enabled": true,
"products": [
{
"internalCode": "PROD-001"
},
{
"internalCode": "PROD-002"
}
]
}

Example Usage

const headers = {
Authorization: "YOUR_AUTH_TOKEN",
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
};

const data = {
title: "Summer Points Challenge",
internalCode: "CHALLENGE-001",
description: "Earn 100 points when you spend $500 on summer products",
image: "https://example.com/challenge.jpg",
pointsGiven: 100,
requiredAmount: 500,
start: "2025-06-01",
end: "2025-08-31",
enabled: true,
products: [
{ internalCode: "PROD-001" },
{ internalCode: "PROD-002" },
],
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/loyaltychallenge",
{
method: "PUT",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Change Loyalty Challenge Status

PUT/loyaltychallenge/{code}/status

Enable or disable a specific loyalty challenge.

Path Parameters

ParameterTypeRequiredDescription
codestringYesInternal code of the loyalty challenge

Request Body Parameters

ParameterTypeRequiredDescription
enabledbooleanYesNew status of the challenge

Request Body Example

{
"enabled": true
}

Example Usage

const headers = {
Authorization: "YOUR_AUTH_TOKEN",
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
};

const data = {
enabled: false,
};

fetch(
"https://tm0cs5kjs6.execute-api.us-east-1.amazonaws.com/dev/loyaltychallenge/CHALLENGE-001/status",
{
method: "PUT",
headers: headers,
body: JSON.stringify(data),
}
)
.then((response) => response.json())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));

Security

Authentication

All endpoints require two types of authentication:

  • API Key in header: x-api-key
  • Authorization token in header: Authorization

Required Permissions

  • For reading operations: supplier/loyaltychallenge.read
  • For writing operations: supplier/loyaltychallenge.write