How to loop through array calling REST API using Action

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2020 08:42 PM
How can I loop through an array calling REST API.
I want to call REST API passing values in an array as REST Query Parameters.
I've tried creating an Action with a REST step that will pass Input variable as a Query Parameter. This works OK.
Now, I want to loop through an array calling this Action for each value. Is this possible or do I have to call REST API within the script. That is, use Scheduled Jobs instead of using Flow Designer and Action.
- Labels:
-
Integrations
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2020 09:38 PM
Hello hozawa,
Your assumption is correct if you wish to call REST API multiple times based on some business logic that populates your array and decides number of REST API call. you have to call it via a Script include and use that method to invoke REST API multiple times.
Having said that calling REST API in a loop could be costly affair, so if possible I would recommend to shift loop logic to your rest api and send required data to API as well.
Hope this helps.
Please mark as helpful, if it helped.
Gaurang Soni
aavenir.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2020 10:32 PM
I've had loop in my REST service but found that it'll timeout when the number of records increases. That's why I'm trying to chunk the REST API calls and loop through them.
All will be fine if loop step is supported in Action but it doesn't seem to be new future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2020 10:09 PM
if you are using flow designer then you will have to use either
a) for each if you are storing something in array
b) Do until
sharing links for help
https://developer.servicenow.com/blog.do?p=/tags/flow-designer/
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2020 10:27 PM
I've tried using For and Do loop in Flow Designer but can't find a way to pass variables in an array on each call without having to save the array in a table.
Is there a way to loop through an array with For or Do loop?