HTTP Request Retries

When working with external APIs, network failures and temporary service outages are inevitable. The retry option in lam.httpRequest and lam.httpRequests allows you to automatically retry failed requests.

The retry functionality is optional, just add a retry object with maxAttempts to your HTTP request.

Important: Retries are not enabled by default. You must explicitly specify retry behaviour when creating your workflow steps.

Example: Suppose we're processing orders and need to reliably send them to external fulfillment services that occasionally experience temporary outages.

1

Send Order to Primary Warehouse (With Retry)

(data) => {
  const { input } = data;

  return {
    "lam.httpRequest": {
      method: "POST",
      url: "{{config.primaryWarehouseUrl}}/api/orders",
      headers: {
        Authorization: "Bearer {{config.warehouseApiKey}}",
        "Content-Type": "application/json",
      },
      body: {
        orderId: input.orderId,
        items: input.items,
        priority: "high",
        shippingAddress: input.shippingAddress,
      },
      retry: {
        maxAttempts: 3, // added here
      },
    },
  };
};
2

Update Multiple Services (Batch Retry)

(data) => {
  const { input } = data;
  const fulfillmentResponse = data.step_2.response || data.step_1.response;

  return {
    "lam.httpRequests": [
      {
        method: "PUT",
        url: `{{config.orderServiceUrl}}/orders/${input.orderId}/status`,
        headers: {
          Authorization: "Bearer {{config.orderServiceKey}}",
        },
        body: {
          status: "processing",
          trackingNumber: fulfillmentResponse.trackingNumber,
          warehouse: fulfillmentResponse.warehouseId,
        },
        retry: {
          maxAttempts: 2,
        },
      },
      {
        method: "POST",
        url: "{{config.notificationServiceUrl}}/send-confirmation",
        headers: {
          Authorization: "Bearer {{config.notificationKey}}",
        },
        body: {
          customerId: input.customerId,
          orderId: input.orderId,
          trackingNumber: fulfillmentResponse.trackingNumber,
          type: "order_confirmed",
        },
        retry: {
          maxAttempts: 4,
        },
      },
    ],
  };
};

Last updated

Was this helpful?