Search code examples
slack-api

Sharing remote file as a direct message in Slack


I'm trying to share file in slack using the files.remote.share method. It's successfully sent to a public channel but when I try to send the same file as a direct message putting slack user's id in a list of channels I receive the following error:

{"ok":false,"error":"channel_not_found","channel":"Uxxxxxxxx"}

I haven't found any limitation in the docs about sharing files as a direct message.

Request is

curl "https://slack.com/api/files.remote.share?channels=Uxxxxxxxx&external_id=8e1e0bd1-ad56-437d-84fe-83722789cc85" \
     -H 'Authorization: Bearer xoxb-xxxxxxxx' \
     -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8'

Solution

  • The userId is not same as channelId. Required channelId can be fetched by using conversation.open method.

    You can find the details here: https://api.slack.com/methods/conversations.open

    sample response:

    {
        "ok": true,
        "channel": {
            "id": "D069C7QFK"
        }
    }
    

    You can use the channel.id received from conversations.open as parameter in files.remote.share method.