Skip to main content

Overview

After checkout, Henry orchestrates fulfillment across merchants and keeps you updated through the Orders API. Use it to power order history, customer support tools, and backend automations.

Retrieve the latest status

Call GET /orders/{orderId} with the ID returned from checkout. The endpoint is secured with your API key.
async function getOrder(orderId) {
  const res = await fetch(
    `https://api.sandbox.henrylabs.ai/v0/orders/${orderId}`,
    {
      headers: { "x-api-key": process.env.HENRY_API_KEY },
    },
  );

  if (!res.ok) throw new Error(`Unable to fetch order ${orderId}`);
  const payload = await res.json();
  return payload.data;
}

const order = await getOrder("123e4567-e89b-12d3-a456-426614174000");
console.log(order.status, order.statusMessage);
The response includes:
  • status and statusMessage — machine and human-friendly states (for example pending, processing, ordered).
  • Monetary totals: subtotal, tax, shipping, and grandTotal, each returned as strings.
  • products — array of items with productName, quantity, and the metadata you supplied when adding to cart.
  • shippingDetails — validated address and contact information used for fulfillment.

Polling pattern

Henry returns immediately once an order is created, even if downstream merchants are still processing it. Poll the endpoint until the status stabilizes or until you pivot to webhooks.
function pollOrderStatus(orderId, intervalMs = 5000) {
  let timer;

  const stop = () => clearInterval(timer);
  timer = setInterval(async () => {
    const order = await getOrder(orderId);
    console.log(`${orderId}: ${order.status}`);

    if (["delivered", "cancelled", "failed"].includes(order.status)) {
      stop();
    }
  }, intervalMs);

  return stop;
}

const stopPolling = pollOrderStatus(order.id);
Persist statusMessage alongside status so support teams can read the canonical explanation without cross-referencing merchant dashboards.

Handling errors

  • 401 Unauthorized — confirm the correct API key for your environment.
  • 404 Order not found — the order ID may be invalid or belongs to a different environment (sandbox vs production).
  • 500 Internal Server Error — rare, but retry with exponential backoff; if it persists, share the orderId and timestamp with support.
Looking for real-time updates? Reach out to your Henry account team to enable beta webhooks for order lifecycle events.