Sending webhook to channel via channel ID

For feature requests, please see: https://mattermost.com/suggestions/.

For troubleshooting questions, please post in the following format:

Summary
I’m trying to create a script that, given a channel ID (the one looking like garbage, such as c83momjurtb9tyort87onf931z, which is visible in the chat info side panel), sends a message there using incoming webhooks. Failed so far: I can only send messages to public channels by their name, e.g. town-square, or to people via @username.

Steps to reproduce

  1. create a webhook
  2. pick a channel ID e.g. your own chat or a 1-1 chat
  3. curl to it: curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "yay!", "channel": "c83momjurtb9tyort87onf931z"}' https://some.mattermost.server.example/hooks/xxxxxxxxxxxxxxxxxxxxxxxxxx

Expected behavior
The channel receives the message.

Observed behavior
A 404 error is spit out:

{
  "id": "web.incoming_webhook.channel.app_error",
  "message": "Couldn't find the channel.",
  "detailed_error": "resource: Channel id: TeamId=u95g461pewnum8ykeeyj3b4xxy&Name=c83momjurtb9tyort87onf931z",
  "request_id": "u67gps5kwjry9e33awcwgf1omh",
  "status_code": 404
}

I’m using mattermost cloud, so it should be fairly up-to-date.

1 Like

Hi Alessandro,

It seems that you’re encountering an issue when trying to send a message to a channel using an incoming webhook in Mattermost Cloud. The error message suggests that the channel couldn’t be found, resulting in a 404 error.

In Mattermost Cloud, channel IDs are not exposed directly in the UI, so it’s expected that using the channel ID directly in the webhook payload won’t work. Instead, you can use the channel’s name or handle to send messages to specific channels.

To send a message to a channel using an incoming webhook in Mattermost Cloud, follow these steps:

  1. Open the Mattermost user interface and navigate to the channel you want to send a message to.
  2. Click on the channel’s name in the header to open the channel menu.
  3. From the channel menu, select “Integrations” and then “Incoming Webhooks”.
  4. Click on “Add Incoming Webhook” to create a new webhook.
  5. Configure the webhook settings, including the channel to post messages to, and save the webhook.
  6. The webhook URL will be provided once the webhook is created. Copy this URL.
  7. Use the copied webhook URL in your curl command to send a message to the channel. Replace the {webhook_url} placeholder with the actual webhook URL, and use the channel name or handle instead of the channel ID in the payload. Here’s an example:
curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "yay!", "channel": "channel_name"}' {webhook_url}

Make sure to replace channel_name with the actual name or handle of the channel you want to send the message to, and {webhook_url} with the copied webhook URL.

By following these steps, you should be able to send a message to a specific channel in Mattermost Cloud using an incoming webhook.

If you have any further questions or need additional assistance, please don’t hesitate to ask!

Best regards,
~Matterbot 1.0

[Disclaimer: This is a new automated response feature we’re testing powered by ChatGPT. Please be aware that this response should be considered as a simulated suggestion and may not always reflect official Mattermost recommendations or support. Use the information provided at your own discretion. Were any of the above suggestions inaccurate? Please feel free to reply with any suggested corrections!]