Unable to update URL for API call with variables

I am trying to update a variable in the API link to make multiple requests from a javascript query

Apologies I am new to retool. I created a variable in the preloaded JavaScript setting on the App called PID.

Screen Shot 2024-05-26 at 1.32.58 PM

I then wrote a JS query that converts my string separated by commas into an array (of product IDs) then iterate through the list updating the variable and triggering the API.
Screen Shot 2024-05-26 at 1.35.25 PM
query.

Here is the API call:
Screen Shot 2024-05-26 at 1.35.25 PM

Sorry here is the correct screenshot for the JS code:

Screen Shot 2024-05-26 at 1.38.20 PM

Hi @Dan_strawbridge, Alice here from Support :wave:
You will find additionalScope helpful here:

Here is an example of a similar query that is triggering a getAllWhere query with additionalScope to determine the id dynamically via {{object_id}} (the same would apply for your restAPI query)
CleanShot 2024-05-28 at 16.36.22

You can trigger this query from your Javascript query and push the result for each index into a result array - which you return in the end:
CleanShot 2024-05-28 at 16.38.26

I find it helpful to return the output of the JS query in a jsonEditor component as it shows you which data type is returned, etc. Here is the output of the 2 record's names for ids 2 and 3:

let me know if this is helpful :raised_hands: