I am trying to use this Azure Serverless IOT Button Project to send an SMS alert: https://azure.microsoft.com/en-in/resources/samples/azure-serverless-iot-button/
When I click the button once, I see that the Logic App starts running multiple times and I get flooded with hundreds of SMS messages in less than a minute. I only need one SMS alert per button click. What am I missing?
"$connections": {
"value": {
"plivo": {
"connectionId": "/subscriptions/---0-fb3c-406e-98--2-7fa0e00ef0d0/resourceGroups/--/providers/Microsoft.Web/connections/plivo",
"connectionName": "plivo",
"id": "/subscriptions/f--0-fb3c-406e-9-72-7f--0/providers/Microsoft.Web/locations/westus/managedApis/plivo"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_SMS": {
"inputs": {
"body": {
"dst": "1 801-999-9999",
"src": "1 801-999-9982",
"text": "Button Pressed - #{triggerBody()?['location']}"
},
"host": {
"connection": {
"name": "#parameters('$connections')['plivo']['connectionId']"
}
},
"method": "post",
"path": "/v1/Account/auth_id_value/Message/"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"location": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
}
}
You have tagged this question with azure-function-app, are you sure the azure function only calls the logic app one time? Could you please post the code of the azure function
I apparently wasnt filtering the messages that were coming through, and so it was triggering on other telemetry that had nothing to do with the buttons.
Related
I'm creating a logic apps standard workflow hosted in an ase v3. I have the built-in file system connector to collect from an on-prem file share. I was able to create the workflow in the azure portal. However, when I return to it and click save I get the following message:
Some of the connections are not authorized yet. If you just created a
workflow from a template, please add the authorized connections to
your workflow before saving
The code for the workflow is shown below:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Copy_file": {
"inputs": {
"parameters": {
"destination": "destination_path_here",
"source": "#triggerOutputs()?['body']?['path']"
},
"serviceProviderConfiguration": {
"connectionName": "FileSystem",
"operationId": "copyFile",
"serviceProviderId": "/serviceProviders/FileSystem"
}
},
"runAfter": {},
"type": "ServiceProvider"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"triggers": {
"When_a_file_is_added": {
"conditions": [
{
"expression": "#not(equals(triggerBody().Size,0))"
}
],
"inputs": {
"parameters": {
"folderPath": "source_path_here"
},
"serviceProviderConfiguration": {
"connectionName": "FileSystem",
"operationId": "whenFilesAreAdded",
"serviceProviderId": "/serviceProviders/FileSystem"
}
},
"kind": "Polling",
"recurrence": {
"frequency": "Second",
"interval": 15
},
"splitOn": "#triggerOutputs()?['body']",
"type": "ServiceProvider"
}
}
},
"kind": "Stateful"
}
I am using "get emails v3" action in "outlook.com" for logic apps. I want to search emails based on subject filters in todays date only. I want following search criteria where I want emails between two times.
((receivedDateTime:#{utcNow()})) BETWEEN (receivedDateTime:#{addToTime(utcNow(), 1, 'Day')})
Is there any way to do that?
After reproducing it was clear that this is because of the format of receivedDateTime is not as same as the format of utcNow(). To achieve your requirement, you need to compare the dates in same format using condition. Below is how I to achieve your requirement using condition action.
Left side Condition
formatDateTime(items('For_each_2')?['receivedDateTime'],'dd/MM/yyyy')
Right side Condition
formatDateTime(addDays(utcNow(), -1), 'dd/MM/yyyy')
Here is the complete flow of my logic app
RESULTS:
Below is the code view of my Logic App
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each_2": {
"actions": {
"Condition": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "Email",
"value": "#items('For_each_2')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"expression": {
"and": [
{
"greaterOrEquals": [
"#formatDateTime(items('For_each_2')?['receivedDateTime'],'dd/MM/yyyy')",
"#formatDateTime(addDays(utcNow(), -1), 'dd/MM/yyyy')"
]
},
{
"lessOrEquals": [
"#formatDateTime(items('For_each_2')?['receivedDateTime'],'dd/MM/yyyy')",
"#formatDateTime(utcNow(),'MM/dd/yyyy')"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"foreach": "#body('Get_emails_(V3)')?['value']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_emails_(V3)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['office365']['connectionId']"
}
},
"method": "get",
"path": "/v3/Mail",
"queries": {
"fetchOnlyFlagged": false,
"fetchOnlyUnread": false,
"fetchOnlyWithAttachment": false,
"folderPath": "Inbox",
"importance": "Any",
"includeAttachments": false
}
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Email",
"type": "array"
}
]
},
"runAfter": {
"Get_emails_(V3)": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/<SUBID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/<SUBID>/providers/Microsoft.Web/locations/centralus/managedApis/office365"
}
}
}
}
}
If I've understood you correctly then this is the sort approach you need to take.
There's an additional parameter to that connector called Search Query.
In there, you can put an expression that looks like the following ...
received>#{formatDateTime(addDays(utcNow(), -1), 'MM/dd/yyyy')}
You're close, if you look at the doco though, the name of the field is different to what comes back in the response.
https://learn.microsoft.com/en-gb/graph/search-query-parameter
You may just need to play around with the formula to give you exactly what you want given the response is all in UTC. I think -1 day is the easiest but it may not be perfect for you.
I have trouble using my array variable in my V2 email in Logic apps. I would like to output my array in the email body. For example if my array is ["1","2",3"]. Im want each value on its own row.
1
2
3
I have 2 issues, outputting my array in the email body(only strings showing in the dynamic menu) and making each value on a row.
After reproducing from my end, I could able to achieve your requirement by replacing "," with "< br>< br>" while sending the email using Send an email (V2) action. Below is the expression that worked for me.
replace(string(variables('SampleArray')),',','<br><br>')
Here is the flow of my Logic App
Result in my Inbox:
To reproduce the same, you can use below codeview in your logicapp
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"SampleArray": {
"inputs": {
"variables": [
{
"name": "SampleArray",
"type": "array",
"value": [
1,
2,
3
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>#{replace(string(variables('SampleArray')),',','<br><br>')}</p>",
"Importance": "Normal",
"Subject": "Sample",
"To": "<YOUR-EMAIL>"
},
"host": {
"connection": {
"name": "#parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"operationOptions": "DisableAutomaticDecompression",
"runAfter": {
"SampleArray": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/<SUB-ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/<SUB-ID>/providers/Microsoft.Web/locations/centralus/managedApis/office365"
}
}
}
}
}
I am trying to deploy the Azure logic app to two environments ie. dev and prod.
I am using a single json file for the logic app and for the environments I have different parameter files. The Azure pipeline picks the parameter file as per the environment. All the parameters defined in the parameters files get bound during deployment, but I'm having issues with the queue name.
This is how I am defining parameters in the parameters files:
"parameters": {
"logicAppName": {
"value": "Test-App-dev"
},
"QueueName": { "value": "testdev" }
}
This is how it is used in path variable in logic app json file:
But after deployment, the queue name is not reflecting on the Azure portal. This is how it looks like in the Azure portal:
After reproducing from our end, we found that this is due to an invalid template. Here is how we could able to pull off the required value.
Created the below parameter
"parameters": {
........
,
"QueueName": {
"defaultValue": "testdev",
"type": "String"
}
}
Now you need to add the same in the template's parameter
"parameters": {
"$connections": {
"value": {
"servicebus_1": {
"connectionId": "[parameters('connections_servicebus_1_externalid')]",
"connectionName": "servicebus-1",
"id": "***"
}
}
},
"QueueNamedev": {
"value": "[parameters('QueueName')]"
}
}
Declare the same in your definition's parameter
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"$QueueNamedev": {
"defaultValue": {},
"type": "String"
}
}
RESULT:
Finally, we could able to read its value as 'testdev'. You can check from parameters that the value of QueueNamedev is read as testdev.
Below is the template of my logic app
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workflows_LogicApp12_name": {
"defaultValue": "LogicApp12",
"type": "String"
},
"connections_servicebus_1_externalid": {
"defaultValue": "/subscriptions/<YourSubscriptionID>/resourceGroups/<YourResourceGroup>/providers/Microsoft.Web/connections/servicebus-1",
"type": "String"
},
"QueueName": {
"defaultValue": "testdev",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[parameters('workflows_LogicApp12_name')]",
"location": "centralus",
"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"
},
"QueueNamedev": {
"defaultValue": {},
"type": "String"
}
},
"triggers": {
"When_a_message_is_received_in_a_queue_(auto-complete)": {
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"evaluatedRecurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['servicebus_1']['connectionId']"
}
},
"method": "get",
"path": "/#{encodeURIComponent(encodeURIComponent(parameters('QueueNamedev')))}/messages/head",
"queries": {
"queueType": "Main"
}
}
}
},
"actions": {},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"servicebus_1": {
"connectionId": "[parameters('connections_servicebus_1_externalid')]",
"connectionName": "servicebus-1",
"id": "/subscriptions/<YourSubscriptionID>/providers/Microsoft.Web/locations/centralus/managedApis/servicebus"
}
}
},
"QueueNamedev": {
"value": "[parameters('QueueName')]"
}
}
}
}
]
}
I try to send list from Web Activity Azure Data Factory, but I cannot make list/array to passed correctly to webhook. Please advice!
I have used this tutorial as base:
https://www.youtube.com/watch?v=ttmETFGYSLg
I have Web activity in Azure Data Factory Posting following body: (this works fine)
{
"ListOfTestNames:" : #{variables('Test_name_list')}
}
I have Logic Apps with "When HTTP request is received".Method is set Post and Schema is followings:
{
"properties": {
"ListOfTestNames": {
"type": "array"
}
},
"type": "object"
}
I have HTTP Webhook in Logic Apps. This works fine and return body including ListOfTestName
#{triggerBody()}
I have HTTP Webhook in Logic Apps:This does not return anything. I wonder why?
#{triggerBody()?['ListOfTestNames']}
I tried both type Array and String
Logic Apps Code: (generated by designer)
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"HTTP_Webhook": {
"inputs": {
"subscribe": {
"body": {
"blocks": [
{
"text": {
"text": "*These are list of names* \n ListOfTestNames #{triggerBody()?['ListOfTestNames:']} ",
"type": "mrkdwn"
},
"type": "section"
},
{
"text": {
"text": "There is currently bug and list of names are not displayed ",
"type": "mrkdwn"
},
"type": "section"
}
]
},
"method": "POST",
"uri": "https://hooks.slack.com/services/11111111111111111111111111111111111111111"
},
"unsubscribe": {}
},
"runAfter": {},
"type": "HttpWebhook"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {
"properties": {
"ListOfTestNames:": {
"type": "array"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
After reproducing the problem on our end, we discovered that the expression you're using is invalid, however it worked when we tried to use
#triggerBody()?['ListOfTestNames']
but not when using
#{triggerBody()?['ListOfTestNames']}
Here are the screenshots for your reference:
When #triggerBody()?['ListOfFiles'] is used:
When #triggerBody() is used :