How to pass an array with curl command for mattermost

384 Views Asked by At

I´m new in Mattermost Rest API world and want to create a direct message channel using curl command. https://api.mattermost.com/#tag/channels/paths/~1channels~1direct/post

I tried this command

curl -i -X POST -H 'Content-Type: application/json' -d '["bot ID", "reciever ID"]' -H 'Authorization: Bearer MyAccessToken' https://myServer/api/v4/channels/direct

but got this issue

{"id":"api.context.invalid_body_param.app_error","message":"Invalid or missing user_id in request body.","detailed_error":"","request_id":"jghjkdfhgjkdfhgjkfh545","status_code":400}

I have the feeling that using array in my curl command is not well formatted or ?

1

There are 1 best solutions below

0
On

I encountered the same issue recently and was able to solve it by sending an array of two identical receiver ids to Mattermost, like so:

curl -i -X POST -H 'Content-Type: application/json' -d '["reciever ID", "reciever ID"]' -H 'Authorization: Bearer MyAccessToken' https://myServer/api/v4/channels/direct

I know it's kinda dumb but it works! If you actually want to send a DM from bot to user, make sure that the bot ID is actually valid and that the bot exist. In my case the integration was acting like a bot but no actual bot user existed.