cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Arshad80
Regular Visitor

Compose the list of IP address to query in next step

Hi All,

 

I am trying to compose each IP address individually out of this below data set received from the step above in my flow.

 

HTTP output

{
"Stats": {
"ExecutionTime": 4.706406,
"resource_usage": {
"cache": {
"memory": {
"hits": 28991,
"misses": 1517,
"total": 30508
},
"disk": {
"hits": 962,
"misses": 0,
"total": 962
}
},
"cpu": {
"user": "00:00:02.0312500",
"kernel": "00:00:00.0937500",
"total cpu": "00:00:02.1250000"
},
"memory": {
"peak_per_node": 100664288
}
},
"dataset_statistics": [
{
"table_row_count": 7,
"table_size": 2010
}
]
},
"Schema": [
{
"Name": "DeviceName",
"Type": "String"
},
{
"Name": "DeviceId",
"Type": "String"
},
{
"Name": "IPAddressHistory",
"Type": "Object"
}
],
"Results": [
{
"DeviceName": "contrihsx1p1rh03.contosotoso.com",
"DeviceId": "f5c2f988d931716a105sdsdsbad32f962a2c3ad9",
"IPAddressHistory": [
"192.168.0.231",
"192.168.0.1",
"192.168.0.230",
"192.168.0.219",
"192.168.0.246",
"192.168.0.244",
"192.168.0.229",
"192.168.0.245",
"192.168.0.2",
"192.168.0.243",
"192.168.0.248",
"192.168.0.235",
"192.168.0.251",
"192.168.0.237",
"192.168.0.239",
"192.168.0.5",
"192.168.0.254",
"192.168.0.238",
"192.168.0.228",
"192.168.0.188",
"192.168.0.232",
"192.168.0.249",
"192.168.0.217",
"192.168.0.233",
"192.168.0.187",
"192.168.0.195",
"192.168.0.240",
"192.168.0.234",
"192.168.0.253",
"192.168.0.255",
"192.168.0.196",
"192.168.0.3",
"192.168.0.194",
"192.168.0.191",
"192.168.0.226",
"192.168.0.186"
]
},
{
"DeviceName": "contoso-ts06.contosotoso.com",
"DeviceId": "f3144d3daeff7dc33457sdsdsffaada2d8dfed8d",
"IPAddressHistory": [
"192.168.0.224",
"192.168.0.236",
"192.168.0.247",
"192.168.0.190"
]
},
{
"DeviceName": "contoso-ts05.contosotoso.com",
"DeviceId": "67011ba531414744c9sdsd118e429aa870fac86",
"IPAddressHistory": [
"192.168.0.6"
]
},
{
"DeviceName": "contoso-ts07.contosotoso.com",
"DeviceId": "2b858dc7810cbe0d61681f3b0e23fd2cf11855b0",
"IPAddressHistory": [
"192.168.0.226",
"192.168.0.242",
"192.168.0.254"
]
},
{
"DeviceName": "contrihsxflhrg42.contosotoso.com",
"DeviceId": "0be54c4506450c313576bsdsd5552600ec60b09",
"IPAddressHistory": [
"192.168.0.237",
"192.168.0.5"
]
},
{
"DeviceName": "contblhsx1z7v6z1.contosotoso.com",
"DeviceId": "3c35acaa031ab5e2cf80wewe42c45022434901bb",
"IPAddressHistory": [
"192.168.0.243",
"192.168.0.252",
"192.168.0.231",
"192.168.0.217",
"192.168.0.233",
"192.168.0.254",
"192.168.0.228",
"192.168.0.8",
"192.168.0.241",
"192.168.0.246",
"192.168.0.235",
"192.168.0.219",
"192.168.0.240",
"192.168.0.242",
"192.168.0.234",
"192.168.0.4",
"192.168.0.3",
"192.168.0.168",
"192.168.0.239"
]
},
{
"DeviceName": "contrihsxc30hhq2.contosotoso.com",
"DeviceId": "ef29677c8e7f11e74ead19b373e4ed51f5f54903",
"IPAddressHistory": [
"192.168.0.224",
"192.168.0.255",
"192.168.0.233",
"192.168.0.248",
"192.168.0.239",
"192.168.0.236"
]
}
]
}

 

I would like remove any duplicate ip address and in the next i would like to query an api :https://www.contoso.com/sa2cpi/c2/ip-address/?ip=eachIPaddress from above

 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

This would be my approach:

https://ibb.co/mcBb9bn

 

IP Address Array.png

Returns a nice clean array of IP Addresses like this, which you can use in a loop:

IP Address Output.PNG

The code for the steps above:

 

Replace Chars Step

replace(replace(variables('HTTP Output'), '"', ''), ',', '')

Split Step

split(outputs('Replace_Chars'), variables('newLine'))

Filter Array Step

indexof(item(), '192.168')

 

Explanation

Basically the entire HTTP output is split into an array of individual lines. That array is then filtered to include only lines which contain "192.168" (as all of your IP addresses do). Then you get an array of IP addresses which you can easily access within a loop.

 

View solution in original post

2 REPLIES 2
abm
Super User
Super User

Hi @Arshad80 

 

You need two ParseJSON steps to achieve this. First pass the full data under the first Parse JSON Step, generate the schema. Next we can get the 'results' which contains all the IPAddress. Declare another Parse JSON and map the results, generate schema. Once you have these you can get all the IPAddress. Declare an array and append all the values into an array. Finally to get the distinct values you could use UNION expression to remove the duplicated values.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials
Paulie78
Super User
Super User

This would be my approach:

https://ibb.co/mcBb9bn

 

IP Address Array.png

Returns a nice clean array of IP Addresses like this, which you can use in a loop:

IP Address Output.PNG

The code for the steps above:

 

Replace Chars Step

replace(replace(variables('HTTP Output'), '"', ''), ',', '')

Split Step

split(outputs('Replace_Chars'), variables('newLine'))

Filter Array Step

indexof(item(), '192.168')

 

Explanation

Basically the entire HTTP output is split into an array of individual lines. That array is then filtered to include only lines which contain "192.168" (as all of your IP addresses do). Then you get an array of IP addresses which you can easily access within a loop.

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (3,775)