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:
- when email arrives, loop through attachments
- when PDF is found, create file in my OneDrive
- get File Content from new file in OneDrive
- use HTTP action to post to https://slack.com/api/files.upload setting properties:
- channels
- filename
- 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