Orders
Endpoints pour créer et consulter les commandes clients
Orders API
Endpoints pour gérer les commandes clients.
Lister les commandes
GET /v1/public-api/orders
Scope requis: read:orders
Paramètres de requête
| Paramètre | Type | Description |
|---|---|---|
page | number | Numéro de page (défaut: 1) |
limit | number | Éléments par page (défaut: 20, max: 100) |
status | string | Filtrer par statut |
customerId | string | Filtrer par client |
dateFrom | string | Date de début (ISO 8601) |
dateTo | string | Date de fin (ISO 8601) |
Exemple de requête
curl -X GET "https://api.nerpsuite.com/v1/public-api/orders?dateFrom=2024-01-01&dateTo=2024-01-31" \
-H "X-API-Key: sk_live_xxx"
Réponse
{
"data": [
{
"id": "ord_abc123",
"orderNumber": "ORD-2024-001234",
"status": "COMPLETED",
"customerId": "cust_001",
"customerName": "Jean Dupont",
"subtotal": 1998.00,
"taxAmount": 359.64,
"discountAmount": 100.00,
"total": 2257.64,
"itemCount": 2,
"items": [
{
"productId": "prod_001",
"productName": "iPhone 15 Pro",
"sku": "IPHONE-15-PRO-128",
"quantity": 1,
"unitPrice": 999.00,
"totalPrice": 999.00
},
{
"productId": "prod_002",
"productName": "AirPods Pro",
"sku": "AIRPODS-PRO-2",
"quantity": 1,
"unitPrice": 999.00,
"totalPrice": 999.00
}
],
"createdAt": "2024-01-25T10:30:00Z"
}
],
"total": 1523,
"page": 1,
"limit": 20,
"totalPages": 77
}
Obtenir une commande
GET /v1/public-api/orders/:id
Scope requis: read:orders
Paramètres de chemin
| Paramètre | Type | Description |
|---|---|---|
id | string | ID de la commande |
Exemple de requête
curl -X GET "https://api.nerpsuite.com/v1/public-api/orders/ord_abc123" \
-H "X-API-Key: sk_live_xxx"
Réponse
Même format que dans la liste, mais pour une seule commande.
Créer une commande
POST /v1/public-api/orders
Scope requis: write:orders
La création de commande décrémente automatiquement le stock des produits concernés.
Corps de la requête
| Champ | Type | Requis | Description |
|---|---|---|---|
customerId | string | Non | ID du client (optionnel pour vente anonyme) |
warehouseId | string | Oui | ID de l'entrepôt source |
items | array | Oui | Liste des articles |
items[].productId | string | Oui | ID du produit |
items[].quantity | number | Oui | Quantité commandée |
items[].unitPrice | number | Non | Prix unitaire (défaut: prix du produit) |
discountAmount | number | Non | Montant de remise globale |
notes | string | Non | Notes sur la commande |
Exemple de requête
curl -X POST "https://api.nerpsuite.com/v1/public-api/orders" \
-H "X-API-Key: sk_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"customerId": "cust_001",
"warehouseId": "wh_001",
"items": [
{
"productId": "prod_001",
"quantity": 2,
"unitPrice": 999.00
},
{
"productId": "prod_003",
"quantity": 1
}
],
"discountAmount": 50.00,
"notes": "Commande web #12345"
}'
Réponse
{
"id": "ord_xyz789",
"orderNumber": "ORD-2024-001235",
"status": "PENDING",
"customerId": "cust_001",
"customerName": "Jean Dupont",
"subtotal": 2048.00,
"taxAmount": 368.64,
"discountAmount": 50.00,
"total": 2366.64,
"itemCount": 3,
"items": [
{
"productId": "prod_001",
"productName": "iPhone 15 Pro",
"sku": "IPHONE-15-PRO-128",
"quantity": 2,
"unitPrice": 999.00,
"totalPrice": 1998.00
},
{
"productId": "prod_003",
"productName": "Coque iPhone 15",
"sku": "CASE-IPHONE-15-BLK",
"quantity": 1,
"unitPrice": 50.00,
"totalPrice": 50.00
}
],
"createdAt": "2024-01-25T14:45:00Z"
}
Statuts de commande
| Statut | Description |
|---|---|
PENDING | Commande créée, en attente de traitement |
PROCESSING | Commande en cours de préparation |
SHIPPED | Commande expédiée |
COMPLETED | Commande livrée/terminée |
CANCELLED | Commande annulée |
Champs de réponse
Commande
| Champ | Type | Description |
|---|---|---|
id | string | Identifiant unique |
orderNumber | string | Numéro de commande lisible |
status | string | Statut de la commande |
customerId | string | ID du client |
customerName | string | Nom du client |
subtotal | number | Sous-total HT |
taxAmount | number | Montant TVA |
discountAmount | number | Montant de remise |
total | number | Total TTC |
itemCount | number | Nombre d'articles |
items | array | Détail des articles |
createdAt | string | Date de création |
Article
| Champ | Type | Description |
|---|---|---|
productId | string | ID du produit |
productName | string | Nom du produit |
sku | string | SKU du produit |
quantity | number | Quantité |
unitPrice | number | Prix unitaire |
totalPrice | number | Prix total ligne |
Erreurs courantes
// Stock insuffisant
{
"statusCode": 422,
"message": "Insufficient stock for product IPHONE-15-PRO-128. Available: 5, Requested: 10",
"error": "Unprocessable Entity"
}
// Produit non trouvé
{
"statusCode": 404,
"message": "Product prod_invalid not found",
"error": "Not Found"
}
// Client non trouvé
{
"statusCode": 404,
"message": "Customer cust_invalid not found",
"error": "Not Found"
}
Cas d'usage
Intégration e-commerce
Synchronisez les commandes de votre boutique en ligne :
async function syncOrderToNerpsuite(shopifyOrder) {
const items = shopifyOrder.line_items.map(item => ({
productId: item.nerpsuite_product_id,
quantity: item.quantity,
unitPrice: parseFloat(item.price)
}));
const response = await fetch('/v1/public-api/orders', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
customerId: shopifyOrder.nerpsuite_customer_id,
warehouseId: 'wh_main',
items,
notes: `Shopify Order #${shopifyOrder.order_number}`
})
});
return response.json();
}