Dynamic parameters URL-API

Bonjour,
Je viens sur ce forum pour vous demander de l'aide.
Je n'arrive pas à rendre l'URL de mon GET dynamique.

Je m'explique :
Je souhaite appeler plusieurs tableaux TRELLO avec un même GET API et pour cela, j'ai un tableau avec des idBoards et j'aimerais que l'URL puisse les charger les uns après les autres.

exemple :
const array = ["1234", "5555", 4566", "9876"]

get url = "https://api.trello.com/1/boards/*****/lists"

et je veux qu'il puisse faire dynamiquement
"https://api.trello.com/1/boards/1234/lists"
"https://api.trello.com/1/boards/5555/lists"
"https://api.trello.com/1/boards/4566/lists"

Pouvez vous m'aider s'il vous plait


Bonjour @Geool

Vous pouvez appeler l'API en transmettant l'ID à l'aide d'un déclencheur dans une requête JS :

const yourArray = ["1234", "5555", "4566","9876"]

for(i=0;i<yourArray.length; i++){

listsByBoard_FOR_FR.trigger({
additionalScope: {
trelloIDs: yourArray[i],
}
})
}

alors dans votre requête listsByBoard_FOR_FR il devrait être boards/{{trelloIDs}}/lists

Désolé, j'ai utilisé Google pour traduire

2 Likes


Hello @ScottR & @victoria,
I tried to do what you wrote but it doesn't work... do you have a more precise idea that could help me?

Hey @Geool! Just to double check, are you running query16 (the JS query) to trigger getData_docusign, or are you triggering it directly? Since we're using additionalScope, we need to make sure we're running the getData query only from the JS query that's able to pass additionalScope in! :slight_smile:

And in case you are already triggering only from the JS query and still getting this error, if you try hardcoding both of the Ids (one at a time), does the getData query work?

Hey @victoria

I did not understand.

Right now, I have a JS request "Query 16" where I copied ScottR's code and a request for the docusign API where I have my url in which I try to inject the "docusignFoldersIDs" variable like ScottR did in his post.

As a result, I don't know how to make the code work.

My request to the API works if I replace the variable with the hard code:

"https://demo.docusign.net/restapi/v2.1/accounts/0d7901d1-5af3-4ba1-b3ab-a55dda9db85d/folders/cf462d81-d56b-4b80-aad5-450920f381b3?include_items=true"

But there will be, in the near future, additional folders so it won't be possible to do all the queries by hand to get the envelopes.

Hey @Geool! If you run the JS query, does it successfully trigger your API queries?

Also, are you trying to return all your API query results together? If so, you might want to try something like this :slightly_smiling_face:

http://community.retool.com/t/how-to-run-a-rest-api-query-for-each-item-in-an-array-and-return-all-results-together/2352

Hey @victoria,
Sorry for the long delay, I was in training.
my request to the api, when I change the variable by a hard data it works. But there, with the code of ScottR it does not work and I do not know why ...

Would you have a solution that works?

Here is the result I get with query 16.

How I can now integrate the result of this query in my URL link in order to get the data of each id.

Thanks for your help

You'll want to do something like this!

http://community.retool.com/t/how-to-run-a-rest-api-query-for-each-item-in-an-array-and-return-all-results-together/2352

const arr = Object.values(query16.data[0])
const query = your_api_query_here

const promises = arr.map((item) => {
    return query.trigger({
      additionalScope: {
        assignment_id: item 
      }
   });
});

return Promise.all(promises)

To explain line 1, it looks like your query16.data is an array of an object like this:

[{0: "336a...", 1: "1edc..."}]

And we want to re-format this to be an array of ids, so we can do:

Object.values(query16.data[0])

to grab the array. Then, we want to trigger your REST API query for each of these ids in your array!

Let me know how this works for you :slight_smile:

Yes, I was inspired by this link to perform my query16. However I receive a complex object that I have to readapt to get only ids in result.

Otherwise, just with the method of the link, here is what I get...


By filtering (because I only need the "envelopeId"), I get the following final result:

But now, I don't know what to put in the URL of my API request so that it automatically retrieves all the data of these ids previously retrieved.

When I put "Object.values(query16.data[0])" in my request it doesn't work ...

So I want to know what to put in this request?

I am desperate :weary:
Thanks for your help and patience

In your request, you’d put the name of your additionalScope variable, which in the example I sent above, it’s {{ assignment_id }}

And make sure you write a separate JS query to run the code I sent above! Make sure to change line 2 to the name of your API query :slight_smile:



(const arr2 is a test)

I don't understand how it works and trying to apply your advice I can't...

I don't know how to make this code work.

Even if I remove the [0], I get my object but the final result is still "undefined" ...

According to you, query16 must stay as it is ?
And I have to create a new query, query22, to remake the method to put it in my getData_docusign2 URL query, right ???

Hey @Geool!

Based on this screenshot, it looks like you might not be passing in the right array of values on lines 1-5. We want to only pass in an array of the IDs. Would you mind if I stepped into your app to take a look?

If so, the name of your app would be very helpful!

Hey @victoria,

yes you can come and have a look and modify the files if needed to make it work.

Here are the files that are being tested to make this dynamic URL work.

Capture d’écran 2023-03-30 à 08.28.27

Thanks again for your patience.

Hey @victoria,

I finally got additionalScope to work!

Sorry again for the many messages and thanks a lot

Awesome!!! So glad to hear you got it to work :slight_smile: Is the rest of your app working as expected?

Thank you
Yes, I am happy too.

Unfortunately no, there is this additionalScope that randomly shows me undefined when I call it with +500 data for the api call.

When I press "run" the application slows down, and takes a long time to return completely random results which I think are not due to the number of calls on the api but maybe to the response time...

Here is the link of the topic created on the forum, thanks for your help