[SOLVED] I cannot post on mattermost through curl. Error 403

Summary

I cannot through curl command line in windows. I get the error:
403: You do not have the appropriate permissions

I can post with my user in the webb-app on this channel. I have tried several public channel that should work fine.

What am I doing wrong?

(Communicating with a Mattermost server version 4.2.0)

Steps to reproduce

curl -i -d “{“login_id”:“ulf.liljengren”,“password”:“pass”}” mattermost-server/api/v4/users/login

  • Copy the Token into next command

curl -i -H “Authorization: Bearer zuhmha33tjnfud1qh1pdk9so3o” -X POST -d “{“username”:“ulf.liljengren”, “channel_id”:“dacu3”,“message”:“Hello World.”}” mattermost-server/api/v4/posts

Expected behavior

Positive response with a post in the wanted channel.

Observed behavior

Console output:

C:\Git\actool\curl-7.56.1-win64-mingw\bin>curl -i -d “{“login_id”:“ulf.liljengren”,“password”:“pass”}” mattermost-server/api/v4/users/login
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 06 Dec 2017 09:24:44 GMT
Content-Type: application/json
Content-Length: 678
Connection: keep-alive
Set-Cookie: MMAUTHTOKEN=zuhmha33tjnfud1qh1pdk9so3o; Path=/; Expires=Fri, 05 Jan 2018 09:24:44 GMT; Max-Age=2592000; Http
Only
Set-Cookie: MMUSERID=4smmi69fatn9bcpdktuie86xoh; Path=/; Expires=Fri, 05 Jan 2018 09:24:44 GMT; Max-Age=2592000
Token: zuhmha33tjnfud1qh1pdk9so3o
X-Request-Id: najzioh8jpgrxdik7ep11d5xeh
X-Version-Id: 4.2.0.4.2.0.24522e3d48cf4c9a00ce1939f093367f.false

{“id”:“4smmi69fatn9bcpdktuie86xoh”,“create_at”:1479461138623,“update_at”:1511273452706,“delete_at”:0,“username”:“ulf.lil
jengren”,“auth_data”:"",“auth_service”:"",“email”:“email”,“email_verified”:true,“nickname”:"",“first_
name”:"",“last_name”:"",“position”:"",“roles”:“system_user”,“allow_marketing”:true,“notify_props”:{“channel”:“true”,“com
ments”:“never”,“desktop”:“mention”,“desktop_duration”:“5”,“desktop_sound”:“false”,“email”:“false”,“first_name”:“false”,“
mention_keys”:“ulf.liljengren”,“push”:“mention”,“push_status”:“online”,“user_id”:“4smmi69fatn9bcpdktuie86xoh”},“last_pas
sword_update”:1511273452706,“last_picture_update”:1479461263140,“locale”:“en”}
C:\Git\actool\curl-7.56.1-win64-mingw\bin>curl -i -H “Authorization: Bearer zuhmha33tjnfud1qh1pdk9so3o” -X POST -d “{“u
sername”:“ulf.liljengren”, “channel_id”:“dacu3”,“message”:“Hello World.”}” mattermost.server/api/v4/posts
HTTP/1.1 403 Forbidden
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 06 Dec 2017 09:25:34 GMT
Content-Type: application/json
Content-Length: 178
Connection: keep-alive
X-Request-Id: uqzgsawp4pbz8kby5tjuo8zhqh
X-Version-Id: 4.2.0.4.2.0.24522e3d48cf4c9a00ce1939f093367f.false

{“id”:“api.context.permissions.app_error”,“message”:“You do not have the appropriate permissions”,“detailed_error”:"",“r
equest_id”:“uqzgsawp4pbz8kby5tjuo8zhqh”,“status_code”:403}

I have started to sniff my own TCP packages to diff how my mattermost web client can post a message and I don´t.

What do I miss in my post request compared to my mattermost web client?

image

I finally solved it!
Apparently “403: You do not have the appropriate permissions” does not only mean you do not have the rights, it also can mean that you cannot find the channel.
I simply misunderstood that the channel_id is not the name of the channel but the id of the channel. Not obvious the first time you try this.
So to get the channel_id you need find out the team_id by the GET team by name call.
Then you can post your message in Mattermost!

Hi @wolfnidh,

Pleased you have resolved your issue! Thanks for posting back the resolution!