Passing loop variables to API query

I have built a workflow to pass fulfilment details (Fulfillment ID, Courier and Tracking Number) from Shipstation to Shopify

That worked fine 1 order at a time but I need to edit the workflow to allow for batches of orders to be passed. I edited the workflow to include a Loop block but I am having difficulty in passing the variables I define in the loop block to values of the variables in the API query.

Loop block code

const results = [];

for (const shipment of Shipstation_GET_order.data.shipments) {
const fulfillmentOrderId = shipment.orderKey;
const company = shipment.carrierCode;
const number = shipment.trackingNumber;

console.log("fulfillmentOrderId:", fulfillmentOrderId);
console.log("company:", company);
console.log("number:", number);

const variables = {
fulfillmentOrderId: fulfillmentOrderId,
company: company,
number: number
};
const result = await query5_lambda.trigger(variables);
results.push(result);
}
return results;

Shopify GraphQL mutation

Variables

I've tried {{fulfillmentOrderId}} {{value.fulfillmentOrderId}} {{query5.fulfillmentOrderId}}

I don't know if I have understood fundamentally how a loop block is set up and the loop code is wrong or if its simpler and I am just not referencing the variables correctly. The error code below suggests a formatting of the data problem, but If I manually enter the details (copy & pasting from thh console log - the API mutation code works fine. Console logging the workflow shows the relevant data is being correctly passed to the loop block.

This is my current error log

I'm on day 3 of trying to work it out! Thanks for any suggestions

I worked it out.

Started again using the GUI default format and simplifying. I realised the variables I needed could be matched from the GET_orders block before and not in the loop code.

1 Like