Histórico de pedidos do usuário
✅ Propósito do cenário:
- O usuário faz login com suas credenciais
- Obtemos o histórico de pedidos do usuário
✅ O que você precisa:
- Uma PROJECT_URL e APP_TOKEN válidas para autenticação com a API OneEntry.
- Usuário registrado com pedidos
📌 Importante:
- Não tratamos erros nesses exemplos.
- Você pode tratar erros em trycatch ou em uma construção como "await Promise.catch((error) => error)"
Cenário
1. Importar oneEntry e definir url e token
Exemplo:
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Criando um cliente API com a função defineOneEntry()
Exemplo:
const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. autenticação com AuthProvider.auth()
Dados:
[
{
"marker": "email_reg",
"value": "your-user@email.com"
},
{
"marker": "password_reg",
"value": "123456"
}
]
Exemplo:
const authResponse = await AuthProvider.auth('email', {
authData,
});
Resultado:
{
"userIdentifier": "your-user@email.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}
4. Obter todos os pedidos do usuário pelo marcador de armazenamento de pedidos com Orders.getAllOrdersByMarker()
Exemplo:
const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30);
Resultado:
{
"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
}
Exemplo final
// 1. Importar oneEntry e definir PROJECT_URL e APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
// 2. Criando um cliente API
const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. autenticação com 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. Obter todos os pedidos do usuário pelo marcador de armazenamento de pedidos com Orders.getAllOrdersByMarker()
const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30);
console.log(allOrders);