Mailtoonedrive

Power BI Admin Ciel 0 Reputation points
2024-05-06T05:59:32.3033333+00:00

can anyone help me on this. I am working on this logic flow where if mail has attachments then store it in one drive. Below is the flow
User's image

I am facing this error while executing
User's image

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,911 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,036 Reputation points
    2024-05-06T08:12:13.8533333+00:00

    @Power BI Admin Ciel Thanks for reaching out. For your requirement, you should use expression items('For_each')?['contentBytes']

    Here is sample code for your reference.

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Compose": {
                    "inputs": "@triggerBody()?['attachments']",
                    "runAfter": {},
                    "type": "Compose"
                },
                "For_each": {
                    "actions": {
                        "Create_file": {
                            "inputs": {
                                "body": "@{items('For_each')?['contentBytes']}",
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['onedriveforbusiness']['connectionId']"
                                    }
                                },
                                "method": "post",
                                "path": "/datasets/default/files",
                                "queries": {
                                    "folderPath": "/Test",
                                    "name": "@{items('For_each')?['name']}"
                                }
                            },
                            "runtimeConfiguration": {
                                "contentTransfer": {
                                    "transferMode": "Chunked"
                                }
                            },
                            "type": "ApiConnection"
                        }
                    },
                    "foreach": "@outputs('Compose')",
                    "runAfter": {
                        "Compose": [
                            "Succeeded"
                        ]
                    },
                    "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": "Id::AAMkADExZTRjNDJmLTMwNzktNGM4ZC05YThmLTQ5NWMwODk0ZGQxMwAuAAAAAABrSNp1lgosTJyDa_IAMdNMAQAMlk7ChMbeS7yA0c_URndrAAOD5QzHAAA=",
                                "importance": "Any",
                                "includeAttachments": true
                            }
                        },
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['office365']['connectionId']"
                            }
                        },
                        "subscribe": {
                            "body": {
                                "NotificationUrl": "@{listCallbackUrl()}"
                            },
                            "method": "post",
                            "pathTemplate": {
                                "template": "/GraphMailSubscriptionPoke/$subscriptions"
                            },
                            "queries": {
                                "fetchOnlyWithAttachment": true,
                                "folderPath": "Id::AAMkADExZTRjNDJmLTMwNzktNGM4ZC05YThmLTQ5NWMwODk0ZGQxMwAuAAAAAABrSNp1lgosTJyDa_IAMdNMAQAMlk7ChMbeS7yA0c_URndrAAOD5QzHAAA=",
                                "importance": "Any"
                            }
                        }
                    },
                    "metadata": {
                        "Id::AAMkADExZTRjNDJmLTMwNzktNGM4ZC05YThmLTQ5NWMwODk0ZGQxMwAuAAAAAABrSNp1lgosTJyDa_IAMdNMAQAMlk7ChMbeS7yA0c_URndrAAOD5QzHAAA=": "Azure SDK"
                    },
                    "splitOn": "@triggerBody()?['value']",
                    "type": "ApiConnectionNotification"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {
                    "office365": {
                        "connectionId": "/subscriptions/
    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
    /resourceGroups/rg/providers/Microsoft.Web/connections/office365-1",
                        "connectionName": "office365-1",
                        "id": "/subscriptions/b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f/providers/Microsoft.Web/locations/southindia/managedApis/office365"
                    },
                    "onedriveforbusiness": {
                        "connectionId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/resourceGroups/rg/providers/Microsoft.Web/connections/onedriveforbusiness",
                        "connectionName": "onedriveforbusiness",
                        "id": "/subscriptions/
    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
    /providers/Microsoft.Web/locations/southindia/managedApis/onedriveforbusiness"
                    }
                }
            }
        }
    }
    
    
    

    If the above solution has helped you, kindly "Accept Answer". If you have further questions regarding this issue, do comment here.