i am using azure service bus queue. but i am not able to get all message from queue using "get all queue message (peek Lock): Microsoft built in api.
Is there any way to get all queue messages?
{
"$connections": {
"value": {
"servicebus_1": {
"connectionId": "/subscriptions/c776fec3-6aec-4722-b099-b054c267b240/resourceGroups/Plugin-Resource/providers/Microsoft.Web/connections/servicebus-3",
"connectionName": "servicebus-3",
"id": "-b054c267b240/providers/Microsoft.Web/locations/northcentralus/managedApis/servicebus"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Get_messages_from_a_queue_(peek-lock)": {
"inputs": {
"host": {
"api": {
"runtimeUrl": "https://logic-apis-northcentralus.azure-apim.net/apim/servicebus"
},
"connection": {
"name": "#parameters('$connections')['servicebus_1']['connectionId']"
}
},
"method": "get",
"path": "/#{encodeURIComponent('email-listener')}/messages/batch/peek",
"queries": {
"maxMessageCount": 20,
"queueType": "Main"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Day",
"interval": 3
},
"type": "Recurrence"
}
}
}
}
thanks
The managed API by default returns 20 messages.
You'll need to manually increase the max message count if you have more than 20 messages in your queue.
Related
As I am a beginner on azue, I would like to know the procedure to follow for the following process:
sending an xml with a service bus message and receiving and parse it with logic app.
Thanks
I have used 2 logic apps in this case where 1 sends an XML message through the service bus and the other receives it.
The flow of Logic App - 1 (Sending XML message to Service bus)
The flow of Logic App - 2 (Receiving XML message from Service bus and parsing it)
You can convert XML to JSON and then use Parse_JSON to parse it.
RESULT:
Codeview of Logic app - 1
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_message": {
"inputs": {
"body": {
"ContentData": "#{base64(outputs('XML_Content'))}",
"SessionId": "#{utcNow()}"
},
"host": {
"connection": {
"name": "#parameters('$connections')['servicebus']['connectionId']"
}
},
"method": "post",
"path": "/#{encodeURIComponent(encodeURIComponent('queue1'))}/messages"
},
"runAfter": {
"XML_Content": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"XML_Content": {
"inputs": "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>",
"runAfter": {},
"type": "Compose"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"servicebus": {
"connectionId": "/subscriptions/<SubId>/resourceGroups/<RG>/providers/Microsoft.Web/connections/servicebus-1",
"connectionName": "servicebus-1",
"id": "/subscriptions/<SubId>/providers/Microsoft.Web/locations/centralus/managedApis/servicebus"
}
}
}
}
}
Codeview of Logic app - 2
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "#json(xml(base64ToString(triggerBody()?['ContentData'])))",
"runAfter": {},
"type": "Compose"
},
"Parse_JSON": {
"inputs": {
"content": "#outputs('Compose')",
"schema": {
"properties": {
"note": {
"properties": {
"body": {
"type": "string"
},
"from": {
"type": "string"
},
"heading": {
"type": "string"
},
"to": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_message_is_received_in_a_queue_(auto-complete)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['servicebus_1']['connectionId']"
}
},
"method": "get",
"path": "/#{encodeURIComponent(encodeURIComponent('queue1'))}/messages/head",
"queries": {
"queueType": "Main"
}
},
"recurrence": {
"frequency": "Second",
"interval": 1
},
"type": "ApiConnection"
}
}
},
"parameters": {
"$connections": {
"value": {
"servicebus_1": {
"connectionId": "/subscriptions/<SubId>/resourceGroups/<RG>/providers/Microsoft.Web/connections/servicebus-2",
"connectionName": "servicebus-2",
"id": "/subscriptions/<SubId>/providers/Microsoft.Web/locations/centralus/managedApis/servicebus"
}
}
}
}
}
I created a trivial Azure Logic App workflow using the designer. The trigger is an Outlook.com connector When_a_new_email_arrives_(V2) that triggers when an email arrives at the configured account with logicapp1 in the subject line.
There is a single action configured which uses another Outlook.com connector Send_an_email_(V2). Both connectors use the same configured connection.
The workflow built in the designer works fine.
The Logic App and its connection are in a Resource Group by themselves. I export the app and connection from the Resource Group and then deploy it to a new Resource Group using the Azure CLI using the following commands:
az group create --name TestGroup1 --location uksouth
az deployment group create --resource-group TestGroup1 --template-file EmailIn-EmailOut.json
The logic app and its connection are correctly created in the new resource group and appear in the designer exactly the same as the original manually created app that works. The connection needs to be manually authenticated by opening it in the Azure Portal and entering the credentials, this is expected.
However the Logic App installed by the cli using the template does not respond to its trigger at all. Manually running the trigger from the Designer in the Azure Portal appears to just hang.
There is no indication given anywhere as to what is failing.
I've spent many hours Googling and trying various things, all to no avail. I don't know what else I can do to get to the bottom of this.
The complete template is included below. I would really appreciate any guidance at all.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"connections_outlook_name": {
"defaultValue": "outlook",
"type": "String"
},
"workflows_EmailIn_EmailOut_name": {
"defaultValue": "EmailIn-EmailOut",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"name": "[parameters('connections_outlook_name')]",
"location": "uksouth",
"kind": "V1",
"properties": {
"displayName": "Outlook.com",
"api": {
"name": "[parameters('connections_outlook_name')]",
"displayName": "Outlook.com",
"description": "Outlook.com connector allows you to manage your mail, calendars, and contacts. You can perform various actions such as send mail, schedule meetings, add contacts, etc.",
"iconUri": "[concat('https://connectoricons-prod.azureedge.net/releases/v1.0.1559/1.0.1559.2723/', parameters('connections_outlook_name'), '/icon.png')]",
"brandColor": "#0078D4",
"id": "[concat('/subscriptions/d2e05926-6db6-4d9d-a091-6f4b5e03a2ec/providers/Microsoft.Web/locations/uksouth/managedApis/', parameters('connections_outlook_name'))]",
"type": "Microsoft.Web/locations/managedApis"
}
}
},
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[parameters('workflows_EmailIn_EmailOut_name')]",
"location": "uksouth",
"dependsOn": [
"[resourceId('Microsoft.Web/connections', parameters('connections_outlook_name'))]"
],
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_new_email_arrives_(V2)": {
"splitOn": "#triggerBody()?['value']",
"type": "ApiConnectionNotification",
"inputs": {
"fetch": {
"method": "get",
"pathTemplate": {
"template": "/v2/Mail/OnNewEmail"
},
"queries": {
"folderPath": "Inbox",
"subjectFilter": "logicapp1"
}
},
"host": {
"connection": {
"name": "#parameters('$connections')['outlook']['connectionId']"
}
},
"subscribe": {
"body": {
"NotificationUrl": "#{listCallbackUrl()}"
},
"method": "post",
"pathTemplate": {
"template": "/MailSubscriptionPoke/$subscriptions"
},
"queries": {
"folderPath": "Inbox"
}
}
}
}
},
"actions": {
"Send_an_email_(V2)": {
"runAfter": {},
"type": "ApiConnection",
"inputs": {
"body": {
"Body": "<p>The logic app executed successfully.</p>",
"Subject": "Logic App executed",
"To": "neutrino_sunset#hotmail.com"
},
"host": {
"connection": {
"name": "#parameters('$connections')['outlook']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
}
}
},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"outlook": {
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('connections_outlook_name'))]",
"connectionName": "outlook",
"id": "/subscriptions/d2e05926-6db6-4d9d-a091-6f4b5e03a2ec/providers/Microsoft.Web/locations/uksouth/managedApis/outlook"
}
}
}
}
}
}
]
}
One work around would be that instead of defining the triggers and action in the Resource try defining them individually in the template
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p><p>The logic app executed successfully.</p></p>",
"Subject": "Logic App executed",
"To": "neutrino_sunset#hotmail.com"
},
"host": {
"connection": {
"referenceName": "outlook"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"triggers": {
"When_a_new_email_arrives_(V2)": {
"inputs": {
"fetch": {
"method": "get",
"pathTemplate": {
"template": "/v2/Mail/OnNewEmail"
},
"queries": {
"fetchOnlyWithAttachment": false,
"folderPath": "Inbox",
"importance": "Any",
"includeAttachments": false,
"subjectFilter": "app"
}
},
"host": {
"connection": {
"referenceName": "outlook"
}
},
"subscribe": {
"body": {
"NotificationUrl": "#{listCallbackUrl()}"
},
"method": "post",
"pathTemplate": {
"template": "/MailSubscriptionPoke/$subscriptions"
},
"queries": {
"fetchOnlyWithAttachment": false,
"folderPath": "Inbox",
"importance": "Any"
}
}
},
"splitOn": "#triggerBody()?['value']",
"type": "ApiConnectionNotification"
}
}
},
"kind": "Stateful"
}
Also along with this the logic app kind must be defined as stateful as the above triggers and actions are not available for stateless .
i have an azure logic app with recurrence that will call api endpoint every midnight, im passing in two date properties in my request body that will include start of day and end of day.
Logic app has expression startOfDay() however they dont have endOfDay(), how can I dynamically get end of day in UTC format like startOfDay() does?
Thanks
this is how my request body looks like but its also complaining about #startOfDay()
{
"organizationId": 'f41186b0-7f09-42c5-8a9d-81a2ad2b0e61',
"attemptedDeliveries": true,
"cancelDateStart": #{startOfDay()},
"cancelDateEnd": ""
}
There is no direct expression for endOfDay but one of the workarounds is to addToTime and 'subtractFromTime' from startOfDay to get the endOfDay. Consider I'm taking the timestamp to be UtcNow() and to calculate the endOfDay I'm using the below expression.
subtractFromTime(addToTime(outputs('startOfDay'),1,'Day','o'),1,'Second','yyyy-MM-ddTHH:mm:ss')
I'm using Parse Json in order to retrieve the inner Json details for future use. By doing this, you can have a custom JSON created using Compose() connector.
Result:-
Codeview
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"attemptedDeliveries": "#body('Parse_JSON')?['attemptedDeliveries']",
"cancelDateEnd": "#{outputs('endOfDay')}",
"cancelDateStart": "#{outputs('startOfDay')}",
"organizationId": "#{body('Parse_JSON')?['organizationId']}"
},
"runAfter": {
"endOfDay": [
"Succeeded"
]
},
"type": "Compose"
},
"Parse_JSON": {
"inputs": {
"content": "#triggerBody()",
"schema": {
"properties": {
"attemptedDeliveries": {
"type": "boolean"
},
"cancelDateEnd": {
"type": "string"
},
"cancelDateStart": {
"type": "string"
},
"organizationId": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {},
"type": "ParseJson"
},
"endOfDay": {
"inputs": "#subtractFromTime(addToTime(startOfDay(utcNow()),1,'Day','o'),1,'Second','yyyy-MM-ddTHH:mm:ss')",
"runAfter": {
"startOfDay": [
"Succeeded"
]
},
"type": "Compose"
},
"startOfDay": {
"inputs": "#startOfDay(utcNow(),'yyyy-MM-ddTHH:mm:ss')",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Compose"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Here is the json that I'm receiving from my body of Http trigger
{
"organizationId": "f41186b0-7f09-42c5-8a9d-81a2ad2b0e61",
"attemptedDeliveries": true,
"cancelDateStart": "",
"cancelDateEnd": ""
}
Updated Answer
After the follow up here my logic app
Result:
Codeview
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"endOfDay": {
"inputs": "#subtractFromTime(addToTime(startOfDay(utcNow()),1,'Day','o'),1,'Second','yyyy-MM-ddTHH:mm:ss')",
"runAfter": {
"startOfDay": [
"Succeeded"
]
},
"type": "Compose"
},
"startOfDay": {
"inputs": "#startOfDay(utcNow(),'yyyy-MM-ddTHH:mm:ss')",
"runAfter": {},
"type": "Compose"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Second",
"interval": 30
},
"recurrence": {
"frequency": "Second",
"interval": 30
},
"type": "Recurrence"
}
}
},
"parameters": {}
}
After endOfDay connector you can add 4 parallel HTTP triggers and add logic to it.
REFERENCES: Reference guide to workflow expression functions in Azure Logic Apps and Power Automate
I am trying to configure a Logic App using Event Grid Trigger. The Trigger should be when my Azure CMK in my key vault is nearing expiry it should send me an email. I have configured the Logic App using the Logic App Designer, but when i try to run the trigger, it throws me the error as shown in the screenshot.
The screenshot for my designer is also attached. Any idea what do i need to do to fix this[![enter image description here][3]][3]
Also putting the code here for reference.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>Your CMK will expire in 30 days</p>",
"ReplyTo": "myemailaddress ",
"Subject": "Key Expiry",
"To": "myemailaddress"
},
"host": {
"connection": {
"name": "#parameters('$connections')['outlook']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_resource_event_occurs": {
"inputs": {
"body": {
"properties": {
"destination": {
"endpointType": "webhook",
"properties": {
"endpointUrl": "#{listCallbackUrl()}"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.KeyVault.KeyNearExpiry"
]
},
"topic": "/subscriptions/<subscriptionid>/resourceGroups/pallabdev/providers/Microsoft.KeyVault/vaults/testhalvault"
}
},
"host": {
"connection": {
"name": "#parameters('$connections')['azureeventgrid_1']['connectionId']"
}
},
"path": "/subscriptions/#{encodeURIComponent('subscriptionId')}/providers/#{encodeURIComponent('Microsoft.KeyVault.vaults')}/resource/eventSubscriptions",
"queries": {
"x-ms-api-version": "2017-06-15-preview"
}
},
"splitOn": "#triggerBody()",
"type": "ApiConnectionWebhook"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureeventgrid_1": {
"connectionId": "/subscriptions/<subscriptionId>/resourceGroups/PallabDev/providers/Microsoft.Web/connections/azureeventgrid",
"connectionName": "azureeventgrid",
"connectionProperties": {
"authentication": {
"type": "ManagedServiceIdentity"
}
},
"id": "/subscriptions/<subscriptionId>/providers/Microsoft.Web/locations/canadacentral/managedApis/azureeventgrid"
},
"outlook": {
"connectionId": "/subscriptions/<subscriptionId>/resourceGroups/PallabDev/providers/Microsoft.Web/connections/outlook",
"connectionName": "outlook",
"id": "/subscriptions/<subscriptionId>/providers/Microsoft.Web/locations/canadacentral/managedApis/outlook"
}
}
}
}
}
The reason is that the triggerbody is null, it needs to be an array, if it is null, it will cause your error.
According to the discussion in the comment area, turning off Split On can avoid this error.
Is it possible to save the response from the HTTP request(First Step) into the Blob Storage(Second Step) while using Azure Logic App.
Thank you.
Yes, You can achieve it by using Http and Create blob task.
Code
{
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/azureblob",
"connectionName": "azureblob",
"id": "/subscriptions/xxx/providers/Microsoft.Web/locations/xxx/managedApis/azureblob"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_blob": {
"inputs": {
"body": "#triggerBody()",
"host": {
"connection": {
"name": "#parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/files",
"queries": {
"folderPath": "/testing",
"name": "Test",
"queryParametersSingleEncoded": true
}
},
"runAfter": {},
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"HTTP": {
"inputs": {
"method": "GET",
"uri": "https://reqres.in/api/users?page=2"
},
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "Http"
}
}
}
}
Update 1:
Just update your blob name with the expression like utcNow('yyyyMMdd')
Presuming you have no extraordinary circumstances, yes, you for sure can save the Request content to a Blob. Any Content really.
You will start with the Create Blob Action specifying the Trigger Body as the content.
Don't over think it, it's the same pattern as saving to a local file.