web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : F7E+xenZrRj/8NLKYpGkLW
Power Automate - Building Flows
Answered

Post File via HTTP

Like (1) ShareShare
ReportReport
Posted on 2 Mar 2017 19:48:58 by 21

I am trying to identify a method to use flow to send the attachment of an email via HTTP Post to a custom API. This API accepts multipart form data with file attachments and works when testing via PostMan. However, when trying to craft together the Flow steps I am unable to emulate the request. 

 

Is there any way to do this type of request via Flow and a custom API?

 

My Setup

Step 1) When an email is flagged. 

Step 2) For each attachment:

   A) HTTP

            Method: POST

            URL: Custom API URL

            Header: { "Content-Type": "application/x-www-form-urlencoded" }

            Body: [attachments]

            Authentication: None

  

When the API recieves the request, it appears to be the encoded file but not in a multipart form request. I have full control over how the API handles the request data so could go about this a different way, but I'm completely stuck with figuring out how the Body field is supposed to behave with an attachment. 

  • tbalci Profile Picture
    6 on 08 Jun 2022 at 07:41:03
    Re: Post File via HTTP

    @SH2021 

    Sorry, I really got confused with another post.

     

  • SH2021 Profile Picture
    89 on 07 Jun 2022 at 16:42:10
    Re: Post File via HTTP

    @tolga-balci Do you mean the damobird post link? https://www.damobird365.com/create-a-draft-email-in-outlook/

  • tolga-balci Profile Picture
    68 on 05 Jun 2022 at 18:59:42
    Re: Post File via HTTP

    Thanks @SH2021  - it seems that I corrected it afterwards, as it seems like there are the underscores, and the error message changed to:

     

    {
     "error": {
     "code": "UnableToDeserializePostBody",
     "message": "were unable to deserialize "
     }
    }

     

     

    Plus, I think we are missing the base64 conversion as documented in the fileAttachments documentation.

     

    Edit: Regarding my post on 30.May, it doesn't appear under my profile. It's as if I posted it and is somehow disappeared. 

    That is a shame, but can you please send me the post's link?

  • SH2021 Profile Picture
    89 on 03 Jun 2022 at 15:32:42
    Re: Post File via HTTP

    I looked at your post now (30.05.22). So you get the same problem is I am facing it seems, the payload error.

    One thing I wonder about is that you have empty spaces in your "name" and "contentBytes":

    “name”:”Monthly Report May 2022.xlsx”,
    “contentBytes”: outputs(‘Get XLSX Report’)?[‘body’]?[‘$content’]


    So far Power Automate has always replaced spaces with lower bars "_" whenever I reference previous steps. It does not seem to like empty spaces. Maybe manually replace them accordingly and try again?

     

    Also: did you try Aud's solution?

  • tolga-balci Profile Picture
    68 on 03 Jun 2022 at 15:08:59
    Re: Post File via HTTP

    Deal. To be honest, I'm following his article, too. I managed to get the drafts working without any issues, but things fail when I try to add the attachments. 

  • SH2021 Profile Picture
    89 on 03 Jun 2022 at 14:51:47
    Re: Post File via HTTP

    Hi@tolga-balci I have not implemented a solution yet, but may have found one. Lately I stumbled upon something which I wanted to try out but then forgot to save the link. It may have been this, because I have not tried this compose idea yet and it looks like it may work: https://www.damobird365.com/create-a-draft-email-in-outlook/

    I will try it out when it becomes relevant for me again (in one month probably), but please let me know if you beat me to it.

    Kind regards

    SH

  • tolga-balci Profile Picture
    68 on 03 Jun 2022 at 14:01:22
    Re: Post File via HTTP

    @SH2021 - I'm struggling with the same for weeks. Were you able to solve your issue? 

  • SH2021 Profile Picture
    89 on 27 Jan 2022 at 15:33:03
    Re: Post File via HTTP

    Thank you for your reply @jjurisch! Unfortunately, I have not solved it, yet, but I might have gotten slightly closer. I used the code below. I got the code for "Attachments" by examining the code of another simple flow which saved this attachment into my sharepoint documents folder, so I can be sure that the information under "Attachments" is correct.

     

    My problematic flow, which I hope will attach this saved file to a draft outlook e-mail using an HTTP POST Request, now gives me a different warning than before: "were unable to deserialize".

     

    Can anyone tell me whether this relates to jjurisch comment about decoding the Base64 string? If yes, I suppose I should parse/decode the string value (meaning the strings of "Id" and "ContentType"? or all fields?) into email values?


    Kind regards

    {
    "subject": "attachment ",
    "body":{
    "contentType":"HTML",
    "content":"Dear X, how are you doing? Bye, Y",
    "Attachments": [
    {
    "@odata.type": "#Microsoft.OutlookServices.FileAttachment",
    "Id": "AAMkADkwOWU0MG…
    "LastModifiedDateTime": "2022-01-27T15:06:43+00:00",
    "Name": "test_BB_.xlsx",
    "ContentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "Size": 18246,
    "IsInline": false,
    "ContentId": null,
    "ContentBytes": "UEsDBBQABgAIAAAAIQDuoo…
    }
    ]
    },
    "toRecipients":[
    {
    "emailAddress":{
    "address":"me.me@me.com"}
    }
    ],
    "ccRecipients":[
    {
    "emailAddress":{
    "address":"me.me@me.com"}
    }
    ],

    }

     

     

    I alternatively tried to directly attach the email attachments to the HTTP POST Request (I have to use PA in German). No luck though:

    SH2021_0-1643298984147.pngSH2021_1-1643299010029.png

     

    The error message body upon examining:

    {
      "error": {
        "code""BadRequest",
        "message""Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",
        "innerError": {
          "date""2022-01-27T15:53:51",
          "request-id""ab80e8ef-e4ee-4927-a837-677f510b545c",
          "client-request-id""ab80e8ef-e4ee-4927-a837-677f510b545c"
        }
      }
    }

     

     

  • jjurisch Profile Picture
    21 on 21 Jan 2022 at 15:15:47
    Re: Post File via HTTP

    @SH2021 - most likely our use cases may be different as with mine I was controlling both the Flow application as well as the API it was sending the data to. In this case, I couldn't change anything in the Flow submission (that I could find). However, that was also ~4-5 years ago and I haven't kept up with advancements in PowerApps/Flows.

     

    In my example, the payload that was sent from Flow to the downstream API was out of my control, but in examining what it was sending I found that the JSON line of "ContentBytes" was actually a Base64 encoded string. If you have control in the downstream application to examine that line and Base64 decode it, it will convert into a file if you use the other metadata to encode it correctly (Content Type, Name, etc). 

     

    So if you are sending to Outlook as draft - unless you have the ability to parse/decode the string value into email values this may not help you much. Outside of this specific project I haven't dabbled with Flow/PowerApps since so am not much of a resource in this space. 

     

    Good luck figuring it out! If you do, please add some details to this thread as looks like more people may have similar issues/use cases. 

  • SH2021 Profile Picture
    89 on 21 Jan 2022 at 12:48:26
    Re: Post File via HTTP

    Dear Community

     

    I am facing this problem and I could not find a proper explanation. If anyone knows how to attach documents that are saved in SharePoint to an HTTP POST request used to create draft emails in Outlook, then please share this valuable piece of info!

     

    I want to obtain "test.pptx" which lies in a SharePoint document folder and then attach it to my HTTP POST request. I first import all the data from this folder and then loop through the data in it. When the loop is at the test.pptx file, I obtain the "id" by using the dynamic content "identifier", as well as the "Name" by using "File Name with Extension". Interestingly, "File Name with Extension" gave me the contentType when saving it in an array. 
    I furthermore load the data directly by using the identifier, which gives me the "ContentBytes" and I then get "Size" by using int(length(string(body('Dateiinhalt_abrufen')))) (its in German).

     

    Below is one of many trials. I'd appreciate any feedback! For example, is the positioning of the attachment correct, or should it appear somewhere else?


    Kind regards
    Sean

     

    {

      "subject": "attachment try ",
      "body":{
      "contentType":"HTML",
      "content":"Dear X, how are you doing? Bye, Y",},
      "toRecipients":[
      {
      "emailAddress":{
      "address":"me.me@me.com"}
      }
    ],
      "ccRecipients":[

      {
      "emailAddress":{
      "address":"me.me@me.com"}
      }
    ],
      [{
      "@odata.type": #Microsoft.OutlookServices.FileAttachment,
      "Id": "Shared%2bDocuments%252faktuelles%2bQuartal%252ftest_GH_.pptx" ,
      "Name": "test.pptx" ,
       "ContentType": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
      "Size": 32731,
      "ContentBytes": "UEsDBBQA…”
      }]

    }

     

    Error upon running:

    Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Loading complete