Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Slack's files.list endpoint return an empty files array?

Tags:

slack-api

I'd like to use the Slack API to delete old files from my workspace, as we are running out of space to upload new ones.

I registered an application, installed it on the target workspace, granted the application the files:read and files:write permissions, and then generated a bot token for the application that has the prefix xoxb.

With this token, I made a GET request to the files.list endpoint using Postman:

GET https://slack.com/api/files.list?token=xoxb-xxxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx&count=100&page=1&show_files_hidden_by_limit=true
HTTP/1.1
User-Agent: PostmanRuntime/7.24.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 29879ef1-6da3-4863-8bb9-da8b4d5f740c
Host: slack.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

HTTP/1.1 200 OK
date: Sat, 09 Jan 2021 18:18:42 GMT
server: Apache
x-xss-protection: 0
pragma: no-cache
cache-control: private, no-cache, no-store, must-revalidate
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-slack-req-id: d972daab31ff4fe7a477eb3149ad5260
x-content-type-options: nosniff
referrer-policy: no-referrer
access-control-expose-headers: x-slack-req-id, retry-after
x-slack-backend: r
x-oauth-scopes: files:read,files:write
x-accepted-oauth-scopes: files:read
expires: Mon, 26 Jul 1997 05:00:00 GMT
vary: Accept-Encoding
access-control-allow-headers: slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags
content-encoding: gzip
content-length: 87
content-type: application/json; charset=utf-8
x-envoy-upstream-service-time: 444
x-backend: files_normal files_canary_with_overflow files_control_with_overflow
x-server: slack-www-hhvm-files-iad-jc2v
x-via: envoy-www-iad-4782, haproxy-edge-iad-y1wa
x-slack-shared-secret-outcome: shared-secret
via: envoy-www-iad-4782
{
  "ok": true,
  "files": [],
  "paging": {
    "count": 100,
    "total": 1803,
    "page": 1,
    "pages": 19
  }
}

As you can see, the response contains an empty files[] array, but the paging attribute tells me that there are 1803 files in the workspace.

Why can't I see any of the files in the workspace, even though I have the appropriate scopes and got an HTTP 200 in response?

like image 340
MusikPolice Avatar asked Sep 16 '25 12:09

MusikPolice


1 Answers

I don't know if this is the answer, but it's a workaround:

  • Grant the application the channels:read and channels:join scopes
  • Call the conversations.list endpoint to get a list of channels in the workspace
  • Grab the id attribute of one of the channels that you would like to list files for
  • Call the conversations.join endpoint to add the application to the channel
  • Call the files.list endpoint to get a list of files in that channel.

Presumably, you can iterate over every public channel in the workspace, join each, list its files, and then delete the files older than a certain date.

like image 58
MusikPolice Avatar answered Sep 19 '25 01:09

MusikPolice