const idempotencyKey = '550e8400-e29b-41d4-a716-446655440000';
const orderData = {
customerId: 'cust_123',
items: [...]
};
// First request
const response = await fetch('https://connect.telnesstech.com/api/v2/orders', {
method: 'POST',
headers: {
'X-Idempotency-Key': idempotencyKey,
'X-API-Key': process.env.CONNECT_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify(orderData)
});
const result = await response.json();
// Response: 201 Created
// {"orderId": "1b11f175-f0e6-4b6c-8c4b-4eee806123a3", "status": "CONFIRMED", ...}
// Retry (network timeout, uncertain state)
// Use the same idempotency key and request data
const retryResponse = await fetch('https://connect.telnesstech.com/api/v2/orders', {
method: 'POST',
headers: {
'X-Idempotency-Key': idempotencyKey, // Same key
'X-API-Key': process.env.CONNECT_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify(orderData) // Same data
});
const retryResult = await retryResponse.json();
// Response: 201 Created (identical to first request)
// {"orderId": "1b11f175-f0e6-4b6c-8c4b-4eee806123a3", "status": "CONFIRMED", ...}
// No duplicate order created