Azure Logic App Graph API Save email attachments to azure storage blob

Bowles, Mickey 46 Reputation points
2022-08-25T14:02:57.177+00:00

I am using the GET call: /users/{id | userPrincipalName}/messages/{id}/attachments/{id}/$value to get the contentBytes and type for an attachment. There do not appear to be any actions that can take that data, convert to the file of proper type (in this case, xlsx) and save to a blob. Saving a file to a blob in a logic app is straight forward, it's getting the file from the get call that seems to be the challenge.
Is there an action for this that I have missed?

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

Accepted answer
  1. MayankBargali-MSFT 68,471 Reputation points
    2022-08-25T15:03:21.453+00:00

    @Bowles, Mickey Thanks for reaching out. You should make GET call /users/{id | userPrincipalName}/messages/{id}/attachments/{id} removing the $value so you can get the contentType, name of the file and other details if needed.

    Now you can leverage the Parse JSON action to tokenize your output so you can further use it in your workflow. You can leverage the below schema for your Parse JSON action or leverage the Use sample payload to generate the schema and provide the sample output to generate the schema.

    {  
        "properties": {  
            "@@odata.context": {  
                "type": "string"  
            },  
            "@@odata.mediaContentType": {  
                "type": "string"  
            },  
            "@@odata.type": {  
                "type": "string"  
            },  
            "contentBytes": {  
                "type": "string"  
            },  
            "contentId": {},  
            "contentLocation": {},  
            "contentType": {  
                "type": "string"  
            },  
            "id": {  
                "type": "string"  
            },  
            "isInline": {  
                "type": "boolean"  
            },  
            "lastModifiedDateTime": {  
                "type": "string"  
            },  
            "name": {  
                "type": "string"  
            },  
            "size": {  
                "type": "integer"  
            }  
        },  
        "type": "object"  
    }  
    

    Once you have the tokenized value you can leverage the Create Blob (v2) action and pass the blob name, blob content (convert it to base64ToBinary) along with the content type

    base64ToBinary(body('Parse_JSON')?['contentBytes'])  
    

    234820-image.png

    With the above flow it will save any file format along with the filename and content. Feel free to get back to me if you need any assistance.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful