Mattermost, Inc.

How to create new channel via api?

Create private channel with API request

mattermost 5.5

macbook$ curl --request POST --url ‘http://localhost:8065/api/v4/channels’ --header ‘Authorization: Bemdq7b1h’ --header ‘Content-Type: application/json’ --data ‘{“display_name”:“testviaCurl”,“name”:“testviacurl”,“team_id”:“3”,“purpose”:"",“type”:“P”
}’

Response:
{“id”:“store.sql_channel.get_channels.not_found.app_error”,“message”:“No channels were found”,“detailed_error”:"",“request_id”:“ixcbx9fegsas8r8dpfwa”,“status_code”:404}
Any help appreciated.

Hi @tanya,

This documentation might help: https://api.mattermost.com/#tag/channels%2Fpaths%2F~1channels%2Fpost. Let me know any questions.

Hi, everyone.

For reference purposes, please refer to the cURL command below as an example. Change the "type" to P or O depending on the channel privacy:

ahmaddanial@mattermost:~$ curl -i -X POST -H 'Content-Type: application/json' -d '{"team_id":"<team_id>", "name":"<channel_name>", "display_name":"<display_name>", "purpose":"<channel_purpose>", "header":"<channel_header>", "type":"P"}' -H 'Authorization: Bearer <access_token>' <url>/api/v4/channels
HTTP/1.1 201 Created
Content-Type: application/json
Vary: Accept-Encoding
X-Request-Id: pta3qxazqp8d5xai3am86mtdhy
X-Version-Id: 5.17.0.5.17.0.1674c3c52527898789567f15be6ba835.true
Date: Sun, 01 Dec 2019 22:13:18 GMT
Content-Length: 437

{"id":"w8jqfj1qfpfduxk36fbfgp4ayy","create_at":1575238398378,"update_at":1575238398378,"delete_at":0,"team_id":"<team_id>","type":"O","display_name":"<display_name>","name":"<channel_name>","header":"<channel_header>","purpose":"<channel_purpose>","last_post_at":0,"total_msg_count":0,"extra_update_at":0,"creator_id":"dhnntb7j8f8wjnf8ttqqk64kao","scheme_id":null,"props":null,"group_constrained":null}