Skip to main content

User order history

✅ Purpose of the scenario:

  • The user logs in with their credentials
  • We get the user order history

✅ What you need:

  • A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
  • Registered user with orders

📌 Important:

  • We do not handle errors in these examples.
  • You can handle errors in trycatch or in a construction like "await Promise.catch((error) => error)"

Scenario

1. Import oneEntry and define url and token

Example:

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

2. Creating an API client with defineOneEntry() function

Example:

const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. auth with AuthProvider.auth()

Data:

[
{
"marker": "email_reg",
"value": "your-user@email.com"
},
{
"marker": "password_reg",
"value": "123456"
}
]

Example:

const authResponse = await AuthProvider.auth('email', {
authData,
});
Result:
{
"userIdentifier": "your-user@email.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}

4. Get all user orders by order storage marker with Orders.getAllOrdersByMarker()

Example:

const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30);
Result:
{
"items": [
{
"id": 83,
"storageId": 1,
"createdDate": "2025-04-27T22:07:50.620Z",
"statusIdentifier": "upcoming",
"formIdentifier": "order",
"formData": [
{
"type": "string",
"marker": "name",
"value": "Christina Thomas"
}
],
"attributeSetIdentifier": "order",
"totalSum": "340.00",
"currency": "USD",
"paymentAccountIdentifier": "cash",
"paymentAccountLocalizeInfos": {
"title": "Cash"
},
"products": [
{
"id": 14,
"title": "Green ball",
"sku": null,
"previewImage": [],
"price": 340,
"quantity": 1
}
],
"isCompleted": false
},
{
"id": 84,
"storageId": 1,
"createdDate": "2025-04-27T22:08:22.813Z",
"statusIdentifier": "upcoming",
"formIdentifier": "order",
"formData": [
{
"type": "string",
"marker": "name",
"value": "Christina Thomas"
}
],
"attributeSetIdentifier": "order",
"totalSum": "340.00",
"currency": "USD",
"paymentAccountIdentifier": "cash",
"paymentAccountLocalizeInfos": {
"title": "Cash"
},
"products": [
{
"id": 14,
"title": "Green ball",
"sku": null,
"previewImage": [],
"price": 340,
"quantity": 1
}
],
"isCompleted": false
}
],
"total": 2
}

Final example

// 1. Import oneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

// 2. Creating an API client
const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. auth with AuthProvider.auth()
const authData = [
{
marker: 'email_reg',
value: 'your-user@email.com',
},
{
marker: 'password_reg',
value: '123456',
},
];
const authResponse = await AuthProvider.auth('email', {
authData,
});

// 4. Get all user orders by order storage marker with Orders.getAllOrdersByMarker()
const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30);
console.log(allOrders);