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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to use HTTP Action...
Power Automate
Unanswered

How to use HTTP Action in PowerAutomate to upload a file to a Slack channel using the Slack API "files.upload"

(1) ShareShare
ReportReport
Posted on by 4

I want to get a PDF attachment from my Inbox when an email arrives (I figured that out), then upload that PDF to a Slack channel using Slack's API call "files.upload". I'm having trouble with the "file" property on their API. I have figured out everything else. 

 

My process:

  1. when email arrives, loop through attachments
  2. when PDF is found, create file in my OneDrive
  3. get File Content from new file in OneDrive
  4. use HTTP action to post to https://slack.com/api/files.upload setting properties:
    1. channels 
    2. filename
    3. file

Outgoing payload to Slack:

 

 

{
 "uri": "https://slack.com/api/files.upload",
 "method": "POST",
 "headers": {
 "Authorization": "*sanitized*"
 },
 "body": {
 "$content-type": "multipart/form-data",
 "$multipart": [
 {
 "headers": {
 "Content-Disposition": "form-data; name=\"channels\""
 },
 "body": "C05TDD9KG0K"
 },
 {
 "headers": {
 "Content-Disposition": "form-data; name=\"file\";",
 "Content-Transfer-Encoding": "binary"
 },
 "body": "%PDF-1.7\r\n%\uFFFD\uFFFD\uFFFD\uFFFD\r\n1 0 obj\r\n\u003C\u003C/Type/Catalog/Pages ...
 },
 {
 "headers": {
 "Content-Disposition": "form-data; name=\"filename\""
 },
 "body": "Microsoft Security Slate - September 14 2023.pdf"
 }
 ]
 }
}

 

 

Return message from Slack: 

 

 

{
 "ok": false,
 "error": "no_file_data"
}

 

 

 

Seems like I'm just missing the correct formatting of the file contents for the API's "file" property. Anybody else tackled this one? Thanks in advance!

-Denny

Categories:
I have the same question (0)
  • sandeepstw Profile Picture
    312 Moderator on at

    Hi There,

     


    For Slack's files.upload API, when dealing with the file parameter, you need to ensure you're sending the actual binary data of the file, not its string representation. The file property should contain the actual binary data of the file. You should not include headers like "%PDF-1.7" within the payload directly. Use "Body" from OneDrive's "Get File Content" Directly: When you use the "Get File Content" action from OneDrive, it returns the binary data of the file. Directly use this output as the body for the file property in your multipart form data.

    Multipart formatting should be as follows:


    {
    "uri": "https://slack.com/api/files.upload",
    "method": "POST",
    "headers": {
    "Authorization": "*sanitized*"
    },
    "body": {
    "$content-type": "multipart/form-data",
    "$multipart": [
    {
    "headers": {
    "Content-Disposition": "form-data; name=\"channels\""
    },
    "body": "C05TDD9KG0K"
    },
    {
    "headers": {
    "Content-Disposition": "form-data; name=\"file\";",
    "Content-Type": "application/pdf",
    "Content-Transfer-Encoding": "binary"
    },
    "body": "@{outputs('Get_file_content')}"
    },
    {
    "headers": {
    "Content-Disposition": "form-data; name=\"filename\""
    },
    "body": "Microsoft Security Slate - September 14 2023.pdf"
    }
    ]
    }
    }
    In the file section, the "body": "@{outputs('Get_file_content')}" will insert the binary content from your OneDrive action directly.

     

     

    Please give kudos and mark as solution if it helps.  

      

    Thanks, 

    Sandeep Mishra 

  • dennyregehr Profile Picture
    4 on at

    I tried using "body": "@{outputs('Get_file_content')}" and it sent this to Slack (didn't work):

    {
     "headers": {
     "Content-Disposition": "form-data; name=\"file\"",
     "Content-Type": "application/pdf",
     "Content-Transfer-Encoding": "binary"
     },
     "body": {
     "statusCode": 200,
     "headers": {
     "Cache-Control": "no-cache",
     "Pragma": "no-cache",
     "Accept-Ranges": "bytes",
     "ETag": "\"{C77A4E8D-9869-4E14-909A-9018BDED3EEB},11\"",
     "Location": "https://flow-apim-msmanaged-na-eastus2-01.azure-apim.net/apim/onedriveforbusiness/shared-onedriveforbu-1ecbaf4b-5c2b-4f85-97b6-9c226e55656a/datasets/default/files/b%2521OTSjq6HeeUqmD9fPRcR6kbpZwJS5h0VPnWagYVlbQ59vXaY6s362Qb57TnyNEy5H.01FABHFFMNJZ5MO2MYCRHJBGUQDC662PXL/content?inferContentType=True",
     "x-ms-request-id": "5383aefa-ea0d-4d9a-804c-3ab91b5f6515",
     "X-AspNet-Version": "4.0.30319",
     "X-Powered-By": "ASP.NET",
     "Timing-Allow-Origin": "*",
     "x-ms-apihub-cached-response": "false",
     "x-ms-apihub-obo": "false",
     "Date": "Fri, 22 Sep 2023 16:49:14 GMT",
     "Content-Length": "206987",
     "Content-Type": "application/pdf",
     "Expires": "-1",
     "Content-Disposition": "attachment; filename=\"Microsoft Security Slate - September 21, 2023.pdf\""
     },
     "body": {
     "$content-type": "application/pdf",
     "$content": "JVBERi0xLjcNCiW1tbW1DQoxIDAg..."
     }
     }
     }
  • dennyregehr Profile Picture
    4 on at

    I have found a workaround: Slack API supports sending binary content as parameter named "content" as an alternative to "file". I am having success with the content parameter. I was hoping to get the "file" parameter working instead since that works when using curl. If anyone can help me get this "file" parameter working, please reach out. 

    Thanks, 

    Denny

  • miinn Profile Picture
    2 on at

    miinn_0-1700032531541.png

    1. get File Content from new file in OneDrive
    2. use HTTP action to post to https://slack.com/api/files.upload

    I want to upload files to the slack channel using the method above.
    Please help me to put the right value in the photo.
    I have token and channel id values.

    Please........

     

     

  • Rolson1 Profile Picture
    45 on at

    Did you ever figure this out?

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard