Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Mixing Parameters in Logic Apps with ARM Template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workflowName": {
"type": "string",
"minLength": 1,
"maxLength": 80,
"metadata": {
"description": "Name of the Logic App."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"allowedValues": [
"[resourceGroup().location]",
"australiaeast",
"australiasoutheast",
"brazilsouth",
"centralus",
"eastasia",
"eastus",
"eastus2",
"japaneast",
"japanwest",
"northcentralus",
"northeurope",
"southcentralus",
"southeastasia",
"westeurope",
"westus"
],
"metadata": {
"description": "Location of the Logic App."
}
},
"connectionO365Name": {
"type": "string",
"metadata": {
"description": "O365 connection name"
},
"defaultValue": "office365"
},
"connectionSpoName": {
"type": "string",
"metadata": {
"description": "SharePointOnline connection name"
},
"defaultValue": "sharepointonline"
},
"connectionDisplayName": {
"type": "string",
"metadata": {
"description": "Display name for connections"
}
},
"spoSiteName": {
"type": "string",
"metadata": {
"description": "SharePointOnline site name"
}
},
"spoUploadLocation": {
"type": "string",
"metadata": {
"description": "File upload location on SharePointOnline"
}
},
"o365Recipient": {
"type": "string",
"metadata": {
"description": "Email recipient"
}
}
},
"variables": {
"spo": {
"siteName": "[concat('/datasets/@{encodeURIComponent(encodeURIComponent(''', parameters('spoSiteName'), '''))}', '/triggers/onupdatedfile')]",
"filePathToDelete": "[concat('/datasets/@{encodeURIComponent(encodeURIComponent(''', parameters('spoSiteName'), '''))}', '/files/@{encodeURIComponent(triggerOutputs()[''headers''][''x-ms-file-id''])}')]"
}
},
"resources": [
{
"apiVersion": "2016-06-01",
"name": "[parameters('connectionO365Name')]",
"type": "Microsoft.Web/connections",
"location": "[parameters('location')]",
"properties": {
"displayName": "[parameters('connectionDisplayName')]",
"api":{
"id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', parameters('connectionO365Name'))]"
}
},
"dependsOn": []
},
{
"apiVersion": "2016-06-01",
"name": "[parameters('connectionSpoName')]",
"type": "Microsoft.Web/connections",
"location": "[parameters('location')]",
"properties": {
"displayName": "[parameters('connectionDisplayName')]",
"api":{
"id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', parameters('connectionSpoName'))]"
}
},
"dependsOn": []
},
{
"apiVersion": "2016-06-01",
"name": "[parameters('workflowName')]",
"type": "Microsoft.Logic/workflows",
"location": "[parameters('location')]",
"tags": {
"displayName": "[parameters('workflowName')]"
},
"properties": {
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('connectionO365Name'))]",
"connectionName": "[parameters('connectionO365Name')]",
"id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', parameters('connectionO365Name'))]"
},
"sharepointonline": {
"connectionId": "[resourceId('Microsoft.Web/connections', parameters('connectionSpoName'))]",
"connectionName": "[parameters('connectionSpoName')]",
"id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', parameters('connectionSpoName'))]"
}
}
}
},
"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": {
"OnFileCreatedOrUpdatedInFolder": {
"type": "ApiConnection",
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['sharepointonline']['connectionId']"
}
},
"method": "get",
"path": "[variables('spo').siteName]",
"queries": {
"folderId": "[parameters('spoUploadLocation')]",
"includeFileContent": true,
"inferContentType": true
}
}
}
},
"actions": {
"SendEmailWithOptions": {
"runAfter": {},
"type": "ApiConnectionWebhook",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"path": "/mailwithoptions/$subscriptions",
"body": {
"Message": {
"Body": "@triggerOutputs()['headers']['x-ms-file-name']",
"Importance": "Normal",
"Options": "Leave it, Delete",
"Subject": "A file was uploaded",
"To": "[parameters('o365Recipient')]"
},
"NotificationUrl": "@{listCallbackUrl()}"
}
}
},
"Condition": {
"runAfter": {
"SendEmailWithOptions": [
"Succeeded"
]
},
"type": "If",
"expression": "@equals(body('SendEmailWithOptions')?['SelectedOption'], 'Delete')",
"actions": {
"DeleteFile": {
"runAfter": {},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['sharepointonline']['connectionId']"
}
},
"method": "delete",
"path": "[variables('spo').filePathToDelete]"
}
},
"OnDeletionSuccess": {
"runAfter": {
"DeleteFile": [
"Succeeded"
]
},
"type": "Compose",
"inputs": "File Deleted"
},
"OnDeletionFail": {
"runAfter": {
"DeleteFile": [
"Failed"
]
},
"type": "Compose",
"inputs": "@body('DeleteFile')"
}
},
"else": {
"actions": {
"OnDoNothing": {
"runAfter": {},
"type": "Compose",
"inputs": "@body('SendEmailWithOptions')?['SelectedOption']"
}
}
}
}
},
"outputs": {}
}
}
}
],
"outputs": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment