0

I was trying to figure out how to use a logic app to download a file from the link provided in an outlook email! Any suggestions would be of great help!

I’ve tried using the HTTP connector so far and was wondering if this use case can be implemented using the logic app

1 Answers1

0

Is there a way to use Azure Logic app to read an outlook email which has a link that dowloads a csv file and then store the file in a storage blob?

Yes, you can do by following below design:

enter image description here

Then: enter image description here

Get Attachement (V2)2:

enter image description here

Then:

enter image description here

Full design:

enter image description here

Created a storage account:

enter image description here

After new emails comes with attachment:

enter image description here

Now logic app runs: enter image description here enter image description here In storage account after logic apps runs: enter image description here

enter image description here

Code View :

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Create_blob_(V2)_2": {
                        "inputs": {
                            "body": "@base64ToBinary(body('Get_Attachment_(V2)_2')?['contentBytes'])",
                            "headers": {
                                "ReadFileMetadataFromServer": true
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files",
                            "queries": {
                                "folderPath": "/rithwik",
                                "name": "@body('Get_Attachment_(V2)_2')?['name']",
                                "queryParametersSingleEncoded": true
                            }
                        },
                        "runAfter": {
                            "Get_Attachment_(V2)_2": [
                                "Succeeded"
                            ]
                        },
                        "runtimeConfiguration": {
                            "contentTransfer": {
                                "transferMode": "Chunked"
                            }
                        },
                        "type": "ApiConnection"
                    },
                    "Get_Attachment_(V2)_2": {
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['office365']['connectionId']"
                                }
                            },
                            "method": "get",
                            "path": "/codeless/v1.0/me/messages/@{encodeURIComponent(triggerBody()?['id'])}/attachments/@{encodeURIComponent(items('For_each')?['id'])}"
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "foreach": "@triggerBody()?['attachments']",
                "runAfter": {},
                "type": "Foreach"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_new_email_arrives_(V3)": {
                "inputs": {
                    "fetch": {
                        "method": "get",
                        "pathTemplate": {
                            "template": "/v3/Mail/OnNewEmail"
                        },
                        "queries": {
                            "fetchOnlyWithAttachment": true,
                            "folderPath": "Inbox",
                            "importance": "Any",
                            "includeAttachments": false
                        }
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "subscribe": {
                        "body": {
                            "NotificationUrl": "@{listCallbackUrl()}"
                        },
                        "method": "post",
                        "pathTemplate": {
                            "template": "/GraphMailSubscriptionPoke/$subscriptions"
                        },
                        "queries": {
                            "fetchOnlyWithAttachment": true,
                            "folderPath": "Inbox",
                            "importance": "Any"
                        }
                    }
                },
                "splitOn": "@triggerBody()?['value']",
                "type": "ApiConnectionNotification"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob": {
                    "connectionId": "/subscriptions/b83c1b83a/resourceGroups/v-rbojja-Mindtree/providers/Microsoft.Web/connections/azureblob",
                    "connectionName": "azureblob",
                    "id": "/subscriptions/b83c1c2/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
                },
                "office365": {
                    "connectionId": "/subscriptions/b83c1ed3-/resourceGroups/bojja/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/b83f/providers/Microsoft.Web/locations/eastus/managedApis/office365"
                }
            }
        }
    }
}
RithwikBojja
  • 5,069
  • 2
  • 3
  • 7