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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Need help with sending...
Power Automate
Suggested Answer

Need help with sending an automated email from Parse JSON step

(0) ShareShare
ReportReport
Posted on by 6
Hello All,
 
I have been asked to see if an automated email can be sent from a mailbox when it detects a certain category. I have at the moment managed to scan the mailbox for a specific category and then parse the email into JSON.
 
The issue I am having is when trying to send an email in the next step it is failing with the following:
 
Flow run failed. Action 'For_each' failed: The execution of template action 'For_each' failed: the result of the evaluation of 'foreach' expression '@outputs('Parse_JSON')?['body']?['body']?['value']' is of type 'Null'. The result must be a valid array.
 
Here is the code for the For Each step:
 
{
  "type": "Foreach",
  "foreach": "@outputs('Parse_JSON')?['body']?['body']?['value']",
  "actions": {
    "Send_an_email_(V2)": {
      "type": "OpenApiConnection",
      "inputs": {
        "parameters": {
          "emailMessage/To": "@items('For_each')?['sender']?['emailAddress']?['address']",
          "emailMessage/Subject": "Test Response",
          "emailMessage/Body": "<p class=\"editor-paragraph\">Test Response</p>",
          "emailMessage/Importance": "Normal"
        },
        "host": {
          "apiId": "/providers/Microsoft.PowerApps/apis/shared_office365",
          "connection": "shared_office365",
          "operationId": "SendEmailV2"
        }
      }
    }
  },
  "runAfter": {
    "Parse_JSON": [
      "Succeeded"
    ]
  }
}
 
I have attached the JSON code.
 
I am not sure what the For Each loop is looking for.
 
Any help would be greatly appreciated.
 
Kind Regards,
Sean Buckle
Code.json

Your file is currently under scan for potential threats. Please wait while we review it for any viruses or malicious content.

Categories:
I have the same question (0)
  • Suggested answer
    Vish WR Profile Picture
    3,748 on at
     
    The error is saying the path outputs('Parse_JSON')?['body']?['body']?['value'] is returning null — so the For Each has nothing to loop over.
     
    The problem is the path is wrong. When you use the Parse JSON action in Power Automate, the output is accessed via body once, not body.body. You've got body twice in the path which is why it's null.
     
    Change your For Each expression from:
    @outputs('Parse_JSON')?['body']?['body']?['value']
     
    to:
    @outputs('Parse_JSON')?['body']?['value']
     
    Also can you share what schema you used in the Parse JSON step? The correct path depends on how your JSON is structured ,if the emails are nested differently the path might need adjusting further. Run the flow once, grab the raw output from the Parse JSON step and check what the actual structure looks like, then match your For Each path to that.
     
    Vishnu WR
     
    Please  Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like 
  • SB-20050811-0 Profile Picture
    6 on at
    Hello Vishnu,
     
    Thank you for the response, I am just trying to figure out how to change the For Each Expression in the Parse JSON.
     
    I have also attached the JSON Schema here as well
     
    Sean Buckle
    JSON Schema.txt

    Your file is currently under scan for potential threats. Please wait while we review it for any viruses or malicious content.

  • SB-20050811-0 Profile Picture
    6 on at
    Hello all,
     
    I have changed the For Each loop to the advised, but still getting this:
     
     
    ExpressionEvaluationFailed. 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.
     
     
    this is the JSON Schema:
     
    {
        "type""object",
        "properties": {
            "statusCode": {
                "type""integer"
            },
            "headers": {
                "type""object",
                "properties": {
                    "Cache-Control": {
                        "type""string"
                    },
                    "Transfer-Encoding": {
                        "type""string"
                    },
                    "Strict-Transport-Security": {
                        "type""string"
                    },
                    "request-id": {
                        "type""string"
                    },
                    "client-request-id": {
                        "type""string"
                    },
                    "x-ms-ags-diagnostic": {
                        "type""string"
                    },
                    "x-ms-environment-id": {
                        "type""string"
                    },
                    "x-ms-tenant-id": {
                        "type""string"
                    },
                    "x-ms-subscription-id": {
                        "type""string"
                    },
                    "x-ms-dlp-re": {
                        "type""string"
                    },
                    "x-ms-dlp-gu": {
                        "type""string"
                    },
                    "x-ms-dlp-ef": {
                        "type""string"
                    },
                    "x-ms-mip-sl": {
                        "type""string"
                    },
                    "x-ms-au-creator-id": {
                        "type""string"
                    },
                    "Timing-Allow-Origin": {
                        "type""string"
                    },
                    "x-ms-apihub-cached-response": {
                        "type""string"
                    },
                    "x-ms-apihub-obo": {
                        "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": {
                                "@@odata.etag": {
                                    "type""string"
                                },
                                "id": {
                                    "type""string"
                                },
                                "createdDateTime": {
                                    "type""string"
                                },
                                "lastModifiedDateTime": {
                                    "type""string"
                                },
                                "changeKey": {
                                    "type""string"
                                },
                                "categories": {
                                    "type""array",
                                    "items": {
                                        "type""string"
                                    }
                                },
                                "receivedDateTime": {
                                    "type""string"
                                },
                                "sentDateTime": {
                                    "type""string"
                                },
                                "hasAttachments": {
                                    "type""boolean"
                                },
                                "internetMessageId": {
                                    "type""string"
                                },
                                "subject": {
                                    "type""string"
                                },
                                "bodyPreview": {
                                    "type""string"
                                },
                                "importance": {
                                    "type""string"
                                },
                                "parentFolderId": {
                                    "type""string"
                                },
                                "conversationId": {
                                    "type""string"
                                },
                                "conversationIndex": {
                                    "type""string"
                                },
                                "isDeliveryReceiptRequested": {},
                                "isReadReceiptRequested": {
                                    "type""boolean"
                                },
                                "isRead": {
                                    "type""boolean"
                                },
                                "isDraft": {
                                    "type""boolean"
                                },
                                "webLink": {
                                    "type""string"
                                },
                                "inferenceClassification": {
                                    "type""string"
                                },
                                "sender": {
                                    "type""object",
                                    "properties": {
                                        "emailAddress": {
                                            "type""object",
                                            "properties": {
                                                "name": {
                                                    "type""string"
                                                },
                                                "address": {
                                                    "type""string"
                                                }
                                            }
                                        }
                                    }
                                },
                                "from": {
                                    "type""object",
                                    "properties": {
                                        "emailAddress": {
                                            "type""object",
                                            "properties": {
                                                "name": {
                                                    "type""string"
                                                },
                                                "address": {
                                                    "type""string"
                                                }
                                            }
                                        }
                                    }
                                },
                                "toRecipients": {
                                    "type""array",
                                    "items": {
                                        "type""object",
                                        "properties": {
                                            "emailAddress": {
                                                "type""object",
                                                "properties": {
                                                    "name": {
                                                        "type""string"
                                                    },
                                                    "address": {
                                                        "type""string"
                                                    }
                                                }
                                            }
                                        },
                                        "required": [
                                            "emailAddress"
                                        ]
                                    }
                                },
                                "ccRecipients": {
                                    "type""array"
                                },
                                "bccRecipients": {
                                    "type""array"
                                },
                                "replyTo": {
                                    "type""array"
                                },
                                "flag": {
                                    "type""object",
                                    "properties": {
                                        "flagStatus": {
                                            "type""string"
                                        }
                                    }
                                }
                            },
                            "required": [
                                "@@odata.etag",
                                "id",
                                "createdDateTime",
                                "lastModifiedDateTime",
                                "changeKey",
                                "categories",
                                "receivedDateTime",
                                "sentDateTime",
                                "hasAttachments",
                                "internetMessageId",
                                "subject",
                                "bodyPreview",
                                "importance",
                                "parentFolderId",
                                "conversationId",
                                "conversationIndex",
                                "isDeliveryReceiptRequested",
                                "isReadReceiptRequested",
                                "isRead",
                                "isDraft",
                                "webLink",
                                "inferenceClassification",
                                "sender",
                                "from",
                                "toRecipients",
                                "ccRecipients",
                                "bccRecipients",
                                "replyTo",
                                "flag"
                            ]
                        }
                    }
                }
            }
        }
    }
     
    It does look like to me is that the information is not being passed to the For Each Loop, but there is data there when looking at the raw output.
     
    Any further help would be greatly appreciated
     
    Kind Regards,
    Sean Buckle

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard