Getting null return value when data exists

New Contributor

Getting the following error:

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

The output of the "Parse_JSON" action has data and is below (data has been scrubbed), as is the schema used in the Parse_JSON action. Below is a screen shot of my flow, Any ideas?

{
"body": {
"@odata.context": "https://graph.microsoft.com/beta/$metadata#deviceManagement/virtualEndpoint/cloudPCs",
"value": [
{
"id": "527bd930-a768-4d30-b9e3-d23e195c9cd7",
"displayName": "display name value",
"imageDisplayName": "Windows 10 Enterprise 21H1",
"provisioningPolicyId": "8f282ff5-ff66-463d-ad5d-9544a53003a8",
"provisioningPolicyName": "policy name value",
"onPremisesConnectionName": "Connection name value",
"servicePlanId": "6b97ad6a-be15-4cbe-afbb-4eb74ecb0243",
"servicePlanName": "CloudPC_Lite",
"status": "provisioned",
"userPrincipalName": "upn value",
"lastModifiedDateTime": "2021-07-26T23:46:56Z",
"managedDeviceId": "cb36ab4c-64db-4a90-b8f0-139d3c6db66c",
"managedDeviceName": "device name value",
"aadDeviceId": "87063bac-6042-42de-aa99-72c781be6076",
"gracePeriodEndDateTime": null,
"servicePlanType": "enterprise",
"statusDetails": null
}
]
}
}

CurtisSawin_0-1650898924965.png

 

JSON Schema

{
"type": "object",
"properties": {
"statusCode": {
"type": "integer"
},
"headers": {
"type": "object",
"properties": {
"Transfer-Encoding": {
"type": "string"
},
"Vary": {
"type": "string"
},
"Strict-Transport-Security": {
"type": "string"
},
"request-id": {
"type": "string"
},
"client-request-id": {
"type": "string"
},
"x-ms-ags-diagnostic": {
"type": "string"
},
"OData-Version": {
"type": "string"
},
"Date": {
"type": "string"
},
"Content-Type": {
"type": "string"
},
"Content-Length": {
"type": "string"
}
}
},
"body": {
"type": "object",
"properties": {
"@@odata.context": {
"type": "string"
},
"value": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"displayName": {
"type": "string"
},
"imageDisplayName": {
"type": "string"
},
"provisioningPolicyId": {
"type": "string"
},
"provisioningPolicyName": {
"type": "string"
},
"onPremisesConnectionName": {
"type": "string"
},
"servicePlanId": {
"type": "string"
},
"servicePlanName": {
"type": "string"
},
"status": {
"type": "string"
},
"userPrincipalName": {
"type": "string"
},
"lastModifiedDateTime": {
"type": "string"
},
"managedDeviceId": {
"type": "string"
},
"managedDeviceName": {
"type": "string"
},
"aadDeviceId": {
"type": "string"
},
"gracePeriodEndDateTime": {},
"servicePlanType": {
"type": "string"
},
"statusDetails": {}
},
"required": [
"id",
"displayName",
"imageDisplayName",
"provisioningPolicyId",
"provisioningPolicyName",
"onPremisesConnectionName",
"servicePlanId",
"servicePlanName",
"status",
"userPrincipalName",
"lastModifiedDateTime",
"managedDeviceId",
"managedDeviceName",
"aadDeviceId",
"gracePeriodEndDateTime",
"servicePlanType",
"statusDetails"
]
}
}
}
}
}
}

1 Reply

Got it solved. 

 

When using the flow editor, adding a "set variable" step automatically wraps the action in an "apply to each" step, using body('Parse JSON')?['body']?['value'] as the output to use. Using the expression editor to change this to body('Parse JSON')?['value'] solves this problem. Example screen shots below.


Requiring the author to make this change feels like a bug, as it defeats the purpose of using a no-code tool.

Looking at some other related posts, it may be a result of the JSON having an array named "value" within the "body."  If so...it's definitely a bug.


Fails (which is the default):

janemckinney_2-1650921617540.png

 

Works:

 

janemckinney_3-1650921714894.png