azure-docs
azure-docs copied to clipboard
It's not working - content should be parsed
Hello, Provided instruction is not correct. Send email step can't use Body from HTTP Request because it's Object type
InvalidTemplate. Unable to process template language expressions in action 'Send_an_email_(V2)' inputs at line '0' and column '0': 'The template language expression 'triggerBody()?['subject']' cannot be evaluated because property 'subject' cannot be selected. Array elements can only be selected using an integer index. Please see https://aka.ms/logicexpressions for usage details.'.
First you need to use Data Operation step -> Parse JSON to get string values of each property.
Then in Send email you need to use in For each loop body('Parse_JSON') instead of triggerBody()
After the changes Logic app is working fine
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 07d7fa6c-ff20-a079-9e08-9fa8f6b6e1ed
- Version Independent ID: 21fcbc40-a6bf-8d67-078f-f9838eabe813
- Content: Tutorial - Use IoT Hub events to trigger Azure Logic Apps - Azure Event Grid
- Content Source: articles/event-grid/publish-iot-hub-events-to-logic-apps.md
- Service: iot-hub
- GitHub Login: @philmea
- Microsoft Alias: philmea
@mjuda-bdg Thanks for the feedback! I have assigned the issue to the content author to evaluate and update as appropriate.
#reassign:kgremban
(Phil no longer works in this area.)
@mjuda-bdg thanks for the feedback. Did you by chance paste the JSON code snippet directly into the Request body JSON schema box? Step 3 of Select a Trigger directs users to click the Use sample payload to generate schema and paste the snippet there instead, since it needs to translate it into something for the JSON box. Curious how you did that step.
Hello Winona,
I used Sample payload from instruction and it's not the case. The problem is that in the instruction an Author used Output Body from HTTP Request in the "Send an email (V2)" step. It's incorrect and not working. First you need to parse HTTP Request output with "Parse JSON". And then you can use data from HTTP Request:
@.***
Pozdrawiam/Best regards, Marcin Juda Azure Administrator
From: Winona Azure @.> Sent: wtorek, 16 sierpnia 2022 23:42 To: MicrosoftDocs/azure-docs @.> Cc: Marcin Juda @.>; Mention @.> Subject: Re: [MicrosoftDocs/azure-docs] It's not working - content should be parsed (Issue #93754)
@mjuda-bdghttps://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmjuda-bdg&data=05%7C01%7Cmjuda%40sii.pl%7Cde07ec825ee5484bc0c308da7fd01a26%7Cf9bd6df6c449481fabb537bd036beb76%7C0%7C0%7C637962829021762652%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=F1n2ZHDB6fXlTC8Aj7oeHt2XhpsOWl9D6MpzquSkAZc%3D&reserved=0 thanks for the feedback. Did you by chance paste the JSON code snippet directly into the Request body JSON schema box? Step 3 of Select a Trigger directs users to click the Use sample payload to generate schema and paste the snippet there instead, since it needs to translate it into something for the JSON box. Curious how you did that step.
Reply to this email directly, view it on GitHubhttps://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoftDocs%2Fazure-docs%2Fissues%2F93754%23issuecomment-1217196755&data=05%7C01%7Cmjuda%40sii.pl%7Cde07ec825ee5484bc0c308da7fd01a26%7Cf9bd6df6c449481fabb537bd036beb76%7C0%7C0%7C637962829021762652%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Q6yhj3QcXlzkNTPRK03eMMgKFBMRhBYShR68hOHy2%2B4%3D&reserved=0, or unsubscribehttps://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAVTK4GR2CHEQNXHPOFHHPQTVZQDJFANCNFSM5XQVBN7A&data=05%7C01%7Cmjuda%40sii.pl%7Cde07ec825ee5484bc0c308da7fd01a26%7Cf9bd6df6c449481fabb537bd036beb76%7C0%7C0%7C637962829021762652%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hqHoCHkaG%2FI%2FRIddhPCWW%2B%2FHRWZ1rTHKwoxs%2BUiY8wc%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.@.>>
Hi Marcin, thanks for the specifics. I asked because I did not get an error when testing the tutorial. I did see some screenshots were old and updated those, also added clarity to other steps. But I did have the Body
in my output:
However, using Logic app designer updates the Logic app code view (a JSON file), so below I'll share my end result JSON for you to compare with yours in your Logic app code view. Also note, I used the Office 365 version of Outlook, though I'm not sure if that matters (if you used Outlook.com like the tutorial suggests).
The updated tutorial should be published in the next 24 hours. I'd be curious if you still get an error.
From my Logic app code view in the Azure portal:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>This is an automated message : @{items('For_each')['eventType']}<br>\nat @{items('For_each')['eventTime']}<br>\nIoT Hub: @{items('For_each')?['data']?['hubName']}<br>\nDevice ID: @{items('For_each')?['data']?['deviceId']}<br>\nConnection state: @{items('For_each')?['data']?['deviceConnectionStateEventInfo']}</p>",
"Importance": "Normal",
"Subject": "IoT Hub alert: @{items('For_each')['eventType']}",
"To": "[email protected]"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"foreach": "@triggerBody()",
"runAfter": {},
"type": "Foreach"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {
"items": {
"properties": {
"data": {
"properties": {
"deviceConnectionStateEventInfo": {
"properties": {
"sequenceNumber": {
"type": "string"
}
},
"type": "object"
},
"deviceId": {
"type": "string"
},
"hubName": {
"type": "string"
},
"moduleId": {
"type": "string"
}
},
"type": "object"
},
"dataVersion": {
"type": "string"
},
"eventTime": {
"type": "string"
},
"eventType": {
"type": "string"
},
"id": {
"type": "string"
},
"metadataVersion": {
"type": "string"
},
"subject": {
"type": "string"
},
"topic": {
"type": "string"
}
},
"required": [
"id",
"topic",
"subject",
"eventType",
"eventTime",
"data",
"dataVersion",
"metadataVersion"
],
"type": "object"
},
"type": "array"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/xxxxxx-xxxx-xxxx-xxxx-xxxxxx/providers/Microsoft.Web/locations/my-region/managedApis/office365"
}
}
}
}
}
Thanks again for the feedback. I'm closing this issue, but feel free to reopen if you'd like to continue the conversation. #please-close