Loop Over Line Items in One Code Step

Roadblock: an order webhook has an array of items but your invoicing app takes them one at a time. Transform the whole array in one step instead of five modules.

The Snippet

const order = JSON.parse(input.order);
const lines = order.items.map((item) => ({
  sku: item.sku,
  description: item.name,
  qty: item.quantity,
  total: (item.quantity * item.unit_price).toFixed(2),
}));
return { lines };

Implementation Steps

  1. Parse the order JSON in a code module
  2. Map + reshape each line item in one pass
  3. Feed the result to an iterator module

All templates