Fetch for Rocket Chat

Hello. Can someone help me to convert curl for Rocket Chat to Mikrotik Fetch?

This curl works:

curl -H "x-user-id: MYUSERID" \
-H "x-auth-token: MYUSERTOKEN" \
-H "content-type:application/json" \
https://rocket.example.com/api/v1/chat.postMessage \
-d '{ "channel": "CHANNELID", "text": "test" }'

When I convert in to fetch:

/tool fetch keep-result=no mode=https url=https://rocket.example.com/api/v1/chat.postMessage http-method=post http-header-field="content-type:application/json, x-user-id: MYUSERID, x-auth-token: MYUSERTOKEN" http-data="{\"channel\": CHANNELID, \"text\": \"test\"}"

I get an error:
“failure: Fetch failed with status 400”
Am I missing something?

for sure this must not be doed:

mode=https url=https:
if you use mode, you must not use url protocol and vice-versa

and if you write
, x-user-id: MYUSERID
you create
[SPACE]x-user-id
filed with value
[SPACE]MYUSERID

Do some testing and troubleshooting with localhost and the pc you running from, first to see the differences.
Also you get some more headers with Mikrotik like “Accept-Encoding: deflate, gzip”
And like @rextended says you have to get the correct spaces places. Space | !Space.
Like Hamlet: 2 B | ! 2 B IS ? (sorry i couldn’t resist myself)

ncat -k -l -p 8080



/tool fetch keep-result=no mode=http url=http://192.168.88.254:8080 http-method=post http-header-field="content-type:application/json, x-user-id: MYUSERID, x-auth-token: MYUSERTOKEN" http-data="{\"channel\": CHANNELID, \"text\": \"test\"}"



POST / HTTP/1.1
Accept-Encoding: deflate, gzip
Content-Length: 38
content-type: application/json
Host: 192.168.88.254:8080
User-Agent: MikroTik
x-auth-token:  MYUSERTOKEN
x-user-id:  MYUSERID

{"channel": CHANNELID, "text": "test"}



curl -H "x-user-id: MYUSERID" -H "x-auth-token: MYUSERTOKEN" -H "content-type:application/json" http://localhost:8080 -d '{ "channel": "CHANNELID", "text": "test" }'



POST / HTTP/1.1
Host: localhost:8080
User-Agent: curl/8.10.1
Accept: */*
x-user-id: MYUSERID
x-auth-token: MYUSERTOKEN
content-type:application/json
Content-Length: 42

{ "channel": "CHANNELID", "text": "test" }

Since I already build schemas for REST API, there is a spin off website that converts curl into /tool/fetch so curl2rsc spits out:

/tool/fetch http-method=post url="https://rocket.example.com/api/v1/chat.postMessage" http-data="{ \"channel\": \"CHANNELID\", \"text\": \"test\" }" http-header-field=("x-user-id: MYUSERID","x-auth-token: MYUSERTOKEN","content-type: application/json")

from the curl above (without \ line separators)

curl -H “x-user-id: MYUSERID” -H “x-auth-token: MYUSERTOKEN” -H “content-type:application/json” > https://rocket.example.com/api/v1/chat.postMessage > -d ‘{ “channel”: “CHANNELID”, “text”: “test” }’

It’s the format for http-header-field that is pretty exacting…

So this should be my final tool fetch line so you overwrite the incorrect value.

/tool/fetch keep-result=no mode=https http-method=post url="https://rocket.example.com/api/v1/chat.postMessage" http-data="{ \"channel\": \"CHANNELID\", \"text\": \"test\" }" http-header-field=("x-user-id:MYUSERID", "x-auth-token:MYUSERTOKEN", "Content-Type:application/json", "Accept-Encoding:*", "Accept:*/*")