BETA: Please note that the current endpoints are considered beta. It is possible there may be changes before these endpoints are finalised.
Get a customer
get /organizations/{organizationId}/customers/{customerId}
{
"createdAt": "2021-10-20T14:51:16Z",
"dob": "2021-10-20",
"email": "john@example.com",
"firstName": "John",
"gender": "MALE",
"hasAgreedToMarketing": true,
"id": "01FCCGYZA9JPQ97HBSTKW0KT7P",
"lastName": "Smith",
"phoneNumber": "+61411222333",
"statistics": {
"lastPointsEarnedAt": "2021-08-23T02:06:24.000Z",
"lastPointsRedeemedAt": "2021-03-17T04:27:06.000Z",
"lastSpentAt": "2021-08-23T02:06:23.000Z",
"pointsBalance": 3125,
"totalPointsEarned": 4523,
"totalPointsRedeemed": 1398,
"totalSpend": 3687,
"updatedAt": "2021-03-17T04:27:06.000Z"
},
"updatedAt": "2021-10-21T18:34:45Z"
}
404: not_found: Not Found response.
List all customers for an organization. The result list is paged by 1000 results. Use X-Next-Page to retrieve the next page of results. Tip: Make sure you URI encode your parameter values, for example the + in the phone number should be encoded to %2B.
get /organizations/{organizationId}/customers
[
{
"createdAt": "2021-10-20T14:51:16Z",
"dob": "2021-10-20",
"email": "john@example.com",
"firstName": "John",
"gender": "MALE",
"hasAgreedToMarketing": true,
"id": "01FCCGYZA9JPQ97HBSTKW0KT7P",
"lastName": "Smith",
"phoneNumber": "+61411222333",
"statistics": {
"lastPointsEarnedAt": "2021-08-23T02:06:24.000Z",
"lastPointsRedeemedAt": "2021-03-17T04:27:06.000Z",
"lastSpentAt": "2021-08-23T02:06:23.000Z",
"pointsBalance": 3125,
"totalPointsEarned": 4523,
"totalPointsRedeemed": 1398,
"totalSpend": 3687,
"updatedAt": "2021-03-17T04:27:06.000Z"
},
"updatedAt": "2021-10-21T18:34:45Z"
},
{
"createdAt": "2021-10-20T14:51:16Z",
"dob": "2021-10-20",
"email": "john@example.com",
"firstName": "John",
"gender": "MALE",
"hasAgreedToMarketing": true,
"id": "01FCCGYZA9JPQ97HBSTKW0KT7P",
"lastName": "Smith",
"phoneNumber": "+61411222333",
"statistics": {
"lastPointsEarnedAt": "2021-08-23T02:06:24.000Z",
"lastPointsRedeemedAt": "2021-03-17T04:27:06.000Z",
"lastSpentAt": "2021-08-23T02:06:23.000Z",
"pointsBalance": 3125,
"totalPointsEarned": 4523,
"totalPointsRedeemed": 1398,
"totalSpend": 3687,
"updatedAt": "2021-03-17T04:27:06.000Z"
},
"updatedAt": "2021-10-21T18:34:45Z"
}
]
To sync the full database on a schedule (rather than using webhook events) without needing to refetch all customers can use the sort=updated query parameter.
This will fetch customers starting with those updated most recently.
Continue to fetch next pages until you pass the updated timestamp from the last scheduled run.
The following example demonstrates the approach using fetch in Typescript (note: limited error handling for brevity).
async function getUpdatedCustomers(organizationId: string, updatedAt: Date | null) {
let customers = [];
let path: string | null = `/organizations/${organizationId}/customers?sort=updated`;
do {
const url = new URL(path, "https://api.loke.global");
const response = await fetch(url, {
headers: { Authorization: "Bearer my_access_token" },
});
if (!response.ok) throw new Error("Network response was not OK");
path = response.headers.get("X-Next-Page");
customers.push(await response.json());
const lastCustomer = customers[customers.length - 1];
if (!lastCustomer || (updatedAt && new Date(lastCustomer.updatedAt) < updatedAt)) {
path = null;
}
} while (path);
return { customers, updatedAt: customers[0]?.updatedAt ?? updatedAt };
}
async function doScheduledJob() {
const job = await getMyJob();
const {customers, updatedAt} = await getUpdatedCustomers(
job.organizationId,
job.updatedAt
);
await updateCustomersInMySystem(customers);
await updateMyJob(job.id, { updatedAt });
}
List all customer-lists that a customer is a member of. The result list is paged by 10 results. Use X-Next-Page to retrieve the next page of results
get /organizations/{organizationId}/customers/{customerId}/memberships
[
{
"id": "01FCCGYZA9JPQ97HBSTKW0KT7P",
"name": "Loyal Customers"
},
{
"id": "01FCCGYZA9JPQ97HBSTKW0KT7P",
"name": "Loyal Customers"
}
]
A customer account
A customer list