Create a Slack channel
Automate this endpoint with an AI agent using the 2chat-whatsapp skill:
npx skills add 2ChatCo/agent-skills -s 2chat-whatsapp
This endpoint will let you create a new Slack channel, link it to a WhatsApp group, and add a user for bidirectional message synchronization.
API costโ
Each call to this endpoint deducts 1 API credit from your plan's API credit pool.
Path Parametersโ
| Field | Description | Required |
|---|---|---|
slack_channel_name | Name of the Slack channel to create. Must contain only lowercase letters, numbers, hyphens, and underscores. Maximum length: 80 characters | Yes |
group_uuid_to_assign | UUID of the WhatsApp group to link with the Slack channel | Yes |
user_email_to_assign | Email of the user to add to the Slack channel | Yes |
Invocationโ
- cURL
- Python
- JavaScript
curl --location --request POST 'https://api.p.2chat.io/open/slack/create-channel/my-channel/assign-to-group-uuid/WAG123456789/user-email-to-assign/user@example.com' \
--header 'X-User-API-Key: your_api_key_here'
import requests
import json
url = "https://api.p.2chat.io/open/slack/create-channel/my-channel/assign-to-group-uuid/WAG123456789/user-email-to-assign/user@example.com"
headers = {
'X-User-API-Key': 'your_api_key_here'
}
response = requests.request("POST", url, headers=headers)
print(response.text)
var axios = require('axios');
var config = {
method: 'post',
url: 'https://api.p.2chat.io/open/slack/create-channel/my-channel/assign-to-group-uuid/WAG123456789/user-email-to-assign/user@example.com',
headers: {
'X-User-API-Key': 'your_api_key_here'
}
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Responseโ
The API will respond with the channel details if the invocation succeeded.
{
"success": true,
"data": {
"slack_channel_id": "C0123ABC456",
"slack_channel_name": "my-channel",
"whatsapp_group_uuid": "WAG123456789",
"user_linked_to_channel": "user@example.com"
}
}
Channel created, but the user couldn't be invitedโ
If the channel was created and linked to the WhatsApp group but the user couldn't be added to it (for example, because the email doesn't belong to a member of your Slack workspace), the API still responds with HTTP 200. user_linked_to_channel is null and a warning explains what happened. The channel works: invite the user from Slack.
{
"success": true,
"data": {
"slack_channel_id": "C0123ABC456",
"slack_channel_name": "my-channel",
"whatsapp_group_uuid": "WAG123456789",
"user_linked_to_channel": null
},
"warning": "The channel was created and linked to the WhatsApp group, but we couldn't invite [user@example.com] to it. Make sure the email belongs to a member of your Slack workspace, and invite them from Slack."
}
| Field | Description |
|---|---|
user_linked_to_channel | Email of the user added to the channel, or null if they couldn't be invited |
warning | Only present when the user couldn't be invited. Describes what to do next |
Channel created, but the WhatsApp group couldn't be linkedโ
If the channel was created but couldn't be linked to the WhatsApp group (for example, because the 2Chat bot couldn't join it), the API responds with HTTP 400 and returns the channel in data. The channel isn't deleted and no user is invited. To retry, link that same channel with Link Slack Channel to WhatsApp Group instead of calling this endpoint again: the channel name is already taken.
{
"error": true,
"error_message": "The bot can't join the channel.",
"data": {
"slack_channel_id": "C0123ABC456",
"slack_channel_name": "my-channel"
}
}
Error Responsesโ
| Status Code | Description |
|---|---|
| 400 | Params missing. Received group_uuid_to_assign=[null] |
| 400 | slack_channel_name can't contain special characters. Received slack_channel_name=[invalid-name] |
| 400 | slack_channel_name can't be longer than 80 characters. Received slack_channel_name=[too-long-name] |
| 400 | Channel is already assign to another channel [existing-channel]. Received group_uuid_to_assign=[group-uuid] |
| 400 | Slack configuration is disabled. Reason: [reason] |
| 400 | Error creating the channel. Received response=[error] |
| 400 | The channel was created but couldn't be linked to the WhatsApp group (e.g. The bot can't join the channel.). The response includes the channel in data |
| 404 | Account is None. Please connect your account with Slack |
| 404 | Group not found. Received group_uuid_to_assign=[group-uuid] |
| 404 | Slack configuration not found. Please connect your account with Slack |
| 500 | Something went wrong, please try again |
Notesโ
- The Slack channel name must follow Slack's naming conventions (lowercase letters, numbers, hyphens, and underscores only)
- The WhatsApp group must exist and be accessible to your account
- The user email must belong to a member of your Slack workspace. If it doesn't, the channel is still created and linked, and the response includes a
warning - Your account must have Slack integration properly configured and enabled
- The WhatsApp group must not be already linked to another Slack channel