web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to iterate over js...
Power Automate
Unanswered

How to iterate over json data?

(0) ShareShare
ReportReport
Posted on by 6

Hi All

 

I am trying to create a very simple flow, that calls a foreign currency api, and adds the values into a sharepoint list. This is my first time using Power Automate.

 

I can get it to work, however it is inelegant, I am manually specifying each currency, I want to just be able to iterate over the api result, and it will automatically populate the currency field - ie I can add more currencies to the HTTP request and they will automatically flow into my sharepoint list.

 

I think I need to use a "apply to each" step, but when I try and use the "Rates" dynamics content, the flow fails with the error that "

The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@items('Apply_to_each')' is of type 'Object'. The result must be a valid array.

 

This feels like it should be super easy but I'm missing something 😞 please help. The parse json schema is below, as is my current working Flow.

 

 

{
    "type""object",
    "properties": {
        "base": {
            "type""string"
        },
        "date": {
            "type""string"
        },
        "rates": {
            "type""object",
            "properties": {
                "EUR": {
                    "type""number"
                },
                "USD": {
                    "type""number"
                }
            }
        },
        "success": {
            "type""boolean"
        },
        "timestamp": {
            "type""integer"
        }
    }
}

 

benkenten_0-1684153573697.png

 

Categories:
I have the same question (0)
  • Djuuu Profile Picture
    65 on at

    Could you be so kind and also provide the body if it is not confidential? (from the http step)

     

    Thank you!

  • benken10 Profile Picture
    6 on at

    Yes of course 🙂

     

    {
     "statusCode": 200,
     "headers": {
     "Transfer-Encoding": "chunked",
     "Connection": "keep-alive",
     "CF-Ray": "7c7b806e68aab7f8-AMS",
     "Access-Control-Allow-Origin": "*",
     "CF-Cache-Status": "DYNAMIC",
     "cf-apo-via": "origin,host",
     "RateLimit-Limit": "250",
     "RateLimit-Remaining": "234",
     "RateLimit-Reset": "1336226",
     "X-Cloud-Trace-Context": "1274d9d94337b84f79cd79720595dd2d",
     "X-RateLimit-Limit-Day": "250",
     "X-RateLimit-Limit-Month": "250",
     "X-RateLimit-Remaining-Day": "244",
     "X-RateLimit-Remaining-Month": "234",
     "Report-To": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=UzmkeFbZ4JMOkD6RLkChEmNuV5BNYNyO1c90IY71QG2D1Q804mxVKcYruScPTt1XWG4HWqQhzes5hZpKopHBRHzRPmY2l6CshU9t66W9tA9Gg0GboMe2S6tvY5GzpCyOM2g%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
     "NEL": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}",
     "Vary": "Accept-Encoding",
     "alt-svc": "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400",
     "Date": "Mon, 15 May 2023 12:49:34 GMT",
     "Server": "cloudflare",
     "Content-Type": "application/json",
     "Content-Length": "169"
     },
     "body": {
     "success": true,
     "timestamp": 1684154944,
     "base": "GBP",
     "date": "2023-05-15",
     "rates": {
     "USD": 1.250985,
     "EUR": 1.150343
     }
     }
    }

     

  • Djuuu Profile Picture
    65 on at

    Thank you! Based on the JSON you posted, there is actually only one value & no array. I think that is just a call for one currency - can you please make a http request for more than one curreny and try it again? (or post the http output again here) 🙂

  • benken10 Profile Picture
    6 on at

    It's definitely a call for 2 currencies, if you look at body --> rates there is USD and EUR there. I just have no idea how to extract that in a proper way?

  • Djuuu Profile Picture
    65 on at

    Alright, can you try this JSON Shema, which gives your an array for the rates - i think this is the solution you are looking for 🙂

    Djuuu_0-1684162197705.png

     



    {
    "type": "object",
    "properties": {
    "base": {
    "type": "string"
    },
    "date": {
    "type": "string"
    },
    "rates": {
    "type": "array",
    "items": {
    "type": "object",
    "properties": {
    "currency": {"type": "string"},
    "rate": {"type": "number"}
    },
    "required": ["currency", "rate"]
    }
    },
    "success": {
    "type": "boolean"
    },
    "timestamp": {
    "type": "integer"
    }
    },
    "required": ["base", "date", "rates", "success", "timestamp"]
    }
  • benken10 Profile Picture
    6 on at

    Unfortunately I get a an error on the parse JSON step, saying "Action 'Parse_JSON' failed"

     

    benkenten_0-1684163645517.png

     

  • Djuuu Profile Picture
    65 on at

    Can you caopy&paste the whole content from the json validation from your screenshot? 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard