bolt-js: Unable to upload a file in a direct message using files.completeUploadExternal

When we use files.completeUploadExternal to upload a file in a direct message using Slack userId it throws an error.

Error: invalid_arguments input must match regex pattern: ^[CGDZ][A-Z0-9]{8,}$ [json-pointer:/channel_id]

To reproduce:

  1. Make an API call to files.getUploadURLExternal.
  2. Make a POST API call to the URL received from the above API call.
  3. Make an API call to files.completeUploadExternal using a Slack userId as the channel_id.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@theshdb totally understand, and I mirror your sentiment and I have raised it internally. However, I am only one voice internally and many considerations go into what we do or do not do with the APIs. Priority and product decisions are made by leadership above my paygrade, unfortunately, however, leadership does pay attention to customer feedback that comes in via emails to feedback@slack.com. Please consider emailing there and telling them you have a feature request / complaint about the deprecated API and what you’d like to see as a customer with regards to the new API.

As for retrieving the DM ID, you can use the conversations.open API and provide the U.... encoded user ID as part of the users argument. That should return a payload that looks like:

{
    "ok": true,
    "no_op": true,
    "already_open": true,
    "channel": {
        "id": "D05TKNSGFL3"
    }
}

As for retrieving the DM ID, you can use the conversations.open API and provide the U… encoded user ID as part of [the users argument]

@filmaj Is there another way to get this? This requires the im:write scope, so requires us going through the app review process again.

Thanks for the clarification @filmaj. I’m aware of this functionality. However, my concern is that the deprecated method files.upload allowed us to use Slack userId to post a file in a direct message. So, why are we no longer supporting it in the new API? Can we not update the regex to include U?

If no, then is it possible to retrieve a direct message ID using the Slack user ID via an API?

Great, glad you got it working. I will close this issue now but if there are any more questions here feel free to re-open or file a new issue.

Got it @filmaj. Thanks for providing the solution on how to get the direct message ID.

This is what I’m using now as an alternate solution to post a file to a DM using a Slack user ID.

if (channelId.startsWith("U")) {
          const conversationsResponse = await web.conversations.open({
            users: channelId,
          });
          channelId = conversationsResponse.channel.id;
        }