How to loop through array calling REST API using Action

Hitoshi Ozawa
Giga Sage
Giga Sage

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.

 

 

4 REPLIES 4

Gaurang Soni Aa
Kilo Expert

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

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.

Ankur Bawiskar
Tera Patron
Tera Patron

@hozawa 

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://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/flow-designer/concept...

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/flow-designer/concept...

https://community.servicenow.com/community?id=community_question&sys_id=50ab1221db97db80200f0b55ca96...

https://developer.servicenow.com/blog.do?p=/tags/flow-designer/

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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?