Accessing metadata in Retool workflow loop

I am encountering an issue while trying to access metadata within a Retool workflow loop. I have an API endpoint that I'm triggering using the 'inbound_api_lambda.trigger()' method for each iteration of the loop. The goal is to retrieve specific data from the API response, including the 'location' header, and return an object containing the relevant information along with the corresponding 'booking_id'.

When I test the API endpoint using the REST API component in Retool, I can successfully access the metadata, including the 'location' header, using the path 'response.metadata.headers.location'. The metadata is present in the response object, and I can retrieve the desired information without any issues.

However, when I implement the same logic within the Retool workflow loop, the entire metadata seems to be missing from the response object. I've logged the 'response' object within the loop to inspect its structure, but it appears to be an array without the expected 'metadata' property.

I've double-checked the API endpoint configuration in the workflow to ensure it matches the one used in the REST API, but the issue persists. The absence of the metadata in the response object within the loop prevents me from accessing the required data, such as the 'location' header.

I'm seeking guidance on how to retrieve the metadata within the Retool workflow loop. I'm wondering if there are any known limitations or differences in how metadata is handled between the REST API and the workflow context in Retool.

Any insights or suggestions on how to access the metadata within the loop or alternative approaches to retrieve the necessary data would be greatly appreciated. If additional information or code snippets are needed, please let me know, and I'll provide them to assist in troubleshooting the problem.

Thank you in advance for your help in resolving this issue.

1 Like

Hello @coconeat,

Welcome to the forum!

When using the 'inbound_api_lambda.trigger()' method within a Retool workflow loop, the 'metadata' property of the response object is not available within the loop. This is because the 'metadata' property is only available in the context of the HTTP request-response cycle, and the 'inbound_api_lambda.trigger()' method creates a new request-response cycle for each iteration of the loop.

To access the 'metadata' property within the loop, you can use the 'await' keyword to make the workflow loop asynchronous, which will allow you to use the 'async' versions of the 'inbound_api_lambda.trigger()' method and the 'response.metadata' property.

Here is an example of how you can do this:

let bookings = [];
for (let booking of bookingsArray) {
  let response = await inbound_api_lambda.triggerAsync(booking.api_endpoint);
  let location = response.metadata.headers.location;
  bookings.push({
    booking_id: booking.id,
    location: location,
  });
}

This will create an array of objects containing the 'booking_id' and 'location' for each booking.

Hope this helps!

:grinning:

Patrick

image



Hi Patrick, thank you for your reply. As you can see from my screenshot, even though I used the await function, the metadata feature is still missing.

1 Like