You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By the look of the Slack documentation there are some changes involved in deprecating the legacy api "files.upload"
The new API works in way different way than the old. It uses 3 steps for uploading a single file into a specific channel.
Example how it works with curl.
echo"$(date) test line 1">> testfile.txt
echo"$(date) test line 2">> testfile.txt
echo"$(date) test line 2">> testfile.txt
ll testfile.txt
-rw-rw-r-- 1 peycho peycho 132 Dec 18 14:05 testfile.txt
export SLACK_TOKEN="YOUR-SLACK-AUTH-TOKEN"# Step 1. You can call it metadata step or something like that.# The required files are token, filename and length.
curl -s https://slack.com/api/files.getUploadURLExternal -F "token=$SLACK_TOKEN" -F "filename=testfile.txt" -F "length=132"| python -m json.tool
{
"ok": true,
"upload_url": "https://files.slack.com/upload/v1/CwABAAAAWVERY-LONG-URL",
"file_id": "F485FFDJK61"
}
# Step 2 upload your file by calling this looong upload_url.
curl -s -X POST https://files.slack.com/upload/v1/CwABAAAAWVERY-LONG-URL -F "token=$SLACK_TOKEN" -F filename="@testfile.txt"# The response should look like "OK - 132". I guess this is the size of the file and OK means it's uploaded.# Step 3. Post the file in the channel(s) you want.
curl -s -X POST https://slack.com/api/files.completeUploadExternal -F "token=$SLACK_TOKEN" -F "channel_id=SLACK-CHANNEL-ID" -F "initial_comment=comment=Testing" -F "files=[{'id': 'F485FFDJK61', 'title': 'testfile.txt' }]"| python -m json.tool
The output of the last curl should look like this:
{
"ok": true,
"files": [
{
"id": "*************",
"created": 1734524521,
"timestamp": 1734524521,
"name": "testfile.txt",
"title": "testfile.txt",
"mimetype": "text/plain",
"filetype": "text",
"pretty_type": "Plain Text",
"user": "**********",
"user_team": "************",
"editable": true,
"size": 132,
"mode": "snippet",
"is_external": false,
"external_type": "",
"is_public": true,
"public_url_shared": false,
"display_as_bot": false,
"username": "",
"url_private": "https://files.slack.com/files-pri/*****************/testfile.txt",
"url_private_download": "https://files.slack.com/files-pri/**************/download/testfile.txt",
"permalink": "https://*******.slack.com/files/****************/testfile.txt",
"permalink_public": "https://slack-files.com/********************",
"edit_link": "https://************.slack.com/files/*************/*************/testfile.txt/edit",
"preview": "Wed Dec 18 02:05:23 PM EET 2024 test line 1\nWed Dec 18 02:05:29 PM EET 2024 test line 2\nWed Dec 18 02:05:32 PM EET 2024 test line 3\n",
"preview_highlight": "<div class=\"CodeMirror cm-s-default CodeMirrorServer\">\n<div class=\"CodeMirror-code\">\n<div><pre>Wed Dec 18 02:05:23 PM EET 2024 test line 1</pre></div>\n<div><pre>Wed Dec 18 02:05:29 PM EET 2024 test line 2</pre></div>\n<div><pre>Wed Dec 18 02:05:32 PM EET 2024 test line 3</pre></div>\n<div><pre></pre></div>\n</div>\n</div>\n",
"lines": 4,
"lines_more": 0,
"preview_is_truncated": false,
"comments_count": 0,
"is_starred": false,
"shares": {
"public": {
"**************": [
{
"reply_users": [],
"reply_users_count": 0,
"reply_count": 0,
"ts": "1734524907.257849",
"channel_name": "*********",
"team_id": "********",
"share_user_id": "********",
"source": "UNKNOWN"
}
]
}
},
"channels": [
"SLACK-CHANNEL-ID"
],
"groups": [],
"ims": [],
"has_more_shares": false,
"has_rich_preview": false,
"file_access": "visible"
}
]
}
With this method I can post files in specific channel.
I would strongly suggest to the devs to start planing and use this api since the old one will be deprecated in couple months.
Jenkins and plugins versions report
Environment
What Operating System are you using (both controller, and any agents involved in the problem)?
Jenkins controller running on Ubuntu 22.04.
Jenkins node running on Ubuntu 22.04 with docker container nodes.
Reproduction steps
Jenkins Pipeline
Expected Results
Post a single short message: Uploaded file: testfile.txt
Upload the example content of file testfile.txt in the same slack channel.
Actual Results
The simple message works.
File upload fail with simple error in Jenkins console.
Anything else?
By the look of the Slack documentation there are some changes involved in deprecating the legacy api "files.upload"
The new API works in way different way than the old. It uses 3 steps for uploading a single file into a specific channel.
Example how it works with curl.
The output of the last curl should look like this:
With this method I can post files in specific channel.
I would strongly suggest to the devs to start planing and use this api since the old one will be deprecated in couple months.
Slack docs: https://api.slack.com/changelog/2024-04-a-better-way-to-upload-files-is-here-to-stay
The text was updated successfully, but these errors were encountered: