toolboxImplementation

Event processing requirements

Your webhook endpoint should implement the following processing pattern:

  1. Accept POST requests containing JSON event data

  2. Validate the event structure before processing

  3. Return HTTP 200-299 immediately to acknowledge receipt

  4. Process events asynchronously to prevent timeout

  5. Implement idempotency using the transaction Id field

  6. Handle duplicate events gracefully (at-least-once delivery may send duplicates)

Example webhook implementation

// Node.js/Express example
app.post('/relay-webhook', async (req, res) => {
  try {
    // Immediately acknowledge receipt
    res.status(200).json({ received: true });
    
    // Process asynchronously
    processEventAsync(req.body);
  } catch (error) {
    // Log error but still return 200
    console.error('Error acknowledging event:', error);
    res.status(200).json({ received: true, error: 'logged' });
  }
});

async function processEventAsync(event) {
  // Check for duplicate using transaction ID
  if (await isDuplicate(event.Id)) {
    console.log(`Duplicate event ${event.Id} - skipping`);
    return;
  }
  
  // Process the event
  await saveTransaction(event);
  await updateInventory(event.SoldItems);
  await updateReporting(event);
}

Idempotency implementation

Implement idempotency using the transaction Id field to prevent duplicate processing:


Last updated

Was this helpful?