I am developing an Azure Logic App to handle notifications for several events (near expiry, expired) on Azure Key Vaults. My setup involves an Event Grid for each Key Vault, all sending their events to the same Logic App.
When Event Grid sends events to the Logic App, they come as an array of events. I am trying to use a 'For each' loop in my Logic App to process each of these events individually. Here's the relevant portion of my Logic App:
I have a 'When a HTTP request is received' trigger,
Followed by a 'For each' loop with triggerBody() as the input,
Inside the loop, I have a 'Send an email (V2)' action.
In the 'Send an email (V2)' action, I'm trying to access the properties of each event using the items() function like this:
Event Type: @{items()?['eventType']}
Key Vault Name: @{items()?['data']?['VaultName']}
Object Type: @{items()?['data']?['ObjectType']}
Object Name: @{items()?['data']?['ObjectName']}
Expiry Date: @{items()?['data']?['EXP']}
But when I try to save the Logic App, I get this error message:
Failed to save logic app. The template validation failed: 'The template action 'Send_an_email_(V2)' at line '1' and column '1679' is not valid: "The template language function 'items' must have at least one parameter.".'.
I have reviewed the documentation and understand that items() doesn't require a parameter when used inside a 'For each' loop, as it automatically refers to the current item of the array that 'For each' is looping through.
What am I doing wrong? How can I set up my Logic App to correctly process each event individually using a 'For each' loop and the items() function?
Below is my schema input:
{
"schema": {
"properties": {
"$schema": {
"type": "string"
},
"properties": {
"properties": {
"data": {
"properties": {
"properties": {
"properties": {
"EXP": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"Id": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"NBF": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"ObjectName": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"ObjectType": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"VaultName": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"Version": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"required": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"type": "string"
}
},
"type": "object"
},
"dataVersion": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"eventTime": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"eventType": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"id": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"metadataVersion": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"subject": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
},
"topic": {
"properties": {
"type": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"required": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"type": "string"
}
},
"type": "object"
}
}
sample of the output:
[
{
"id": "5a",
"topic": "/subscriptions/8",
"subject": "kv",
"eventType": "Microsoft.KeyVault.SecretNearExpiry",
"data": {
"Id": "https://kv",
"VaultName": "kv-v",
"ObjectType": "Secret",
"ObjectName": "kv",
"Version": "",
"NBF": null,
"EXP": "2023-06-13T00:00:00Z"
},
"dataVersion": "1",
"metadataVersion": "1",
"eventTime": "2023-06-12T00:00:00Z"
}
]