Execute WSG Request - Parse JSON response fail

I am testing out various flows using the Execute WSG request to pull data from the datasource, but I am running into a problem parsing the JSON response that comes from the Request.

I am trying to run an Apply to Each action for the instances in the response, and then I want to pull back the relatedInstances and the properties associated to that.

Basically we are pulling back User groups and Lists and we want to list out the members of the groups and lists returned by the request.

At present I have stripped the flow back to the absolute basics and when run it looks like this

I'm not sure if the image is working but I have the following;

Manually trigger a flow > Execute WSG Request > Parse JSON > Initialise Variable (Array) > Apply to Each(instances) > (nested) Apply to Each (relatedInstances)  > (nested) Compose(instanceId) >  Append to variable (Array)

No matter what I don I end up with the following error message at the first Apply to Each (instances)

ExpressionEvaluationFailed. The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')?['body']?['body']?['instances']' is of type 'Null'. The result must be a valid array.

Some of the InstanceIds are null value, and I have read on several forums that null values can cause this error, but has anyone else found a way around this, or know of a better solution to extracting the and flattening the JSON structure?

Any help would be greatly appreciated.



  • Hi Paul,

    We have a working flow to list user emails in a group and send an email to all of them as an example. I believe this might help you out as it seems you're close to your result.

    1. WSG Action example to pull a specific user group.

    For performance reasons if you have a single group you might want to just query by PW_WSG/UserCollection/{Your_Collection_Id} and forego Filter query parameter by name.

    2. You need to parse the response JSON to a dynamic object by adding Parse JSON action and selecting JSON body as your input:

    You can either copy/paste the whole schema or very simply generate from sample.

    I used generate from sample:

    {"instances":[{"relationshipInstances": [{"relatedInstance": {"properties": {"Email": ccc@ddd.com}}}]}]}

    3. Generate an array that we will fill by using Initialize variable action:

    4. Loop over the parsed object and append all emails to our array:

    5. Use the result to send an email. In “to” field add an expression to join the array by semicolon:

    Perhaps step 5 is unnecessary for you to replicate and seems that you're trying to "(nested) Compose(instanceId)", but it fails even before that.



    Answer Verified By: Paul Duffy 

  • Thanks for the quick response Aivaras,

    After reading your reply, I still get the same error with my original flow, but I have built a new one and as far as I can tell I have used the same process as before, but I get past the first "apply to each" for "instances", which didn't happen before.

    For the schema I have taken the raw output from the Execute WSG Request and used that as the sample for the template, so my template contains more than I need I think.

    My WSG request looks like this;

    So I am selecting a specific group in the URL, I am looking at other ways to select this group, and then grabbing the user.name. What I have found is that there is no "instanceId" for each of the members, and I was wondering if that is why my first "Apply to each" was failing, as I had read that null values can lead to that error I was having.

    Thanks for your reply though, and that email flow looks interesting. I do have it working now, although my original flow, which looks the same as the new one to me. I have it writing the user names to a SPList for now.

    Thanks again.