Search code examples
curlslackslack-api

How to respond to Slack thread with curl command


I am trying to get my curl to work then i try to create a response to a thread.

I have been following this doc: https://api.slack.com/docs/message-threading#threads_party And from the tester I got the information required to make the call: https://api.slack.com/methods/chat.postMessage/test

If I try to make a curl looking like this:

curl -X POST -H 'Content-type: application/json' --data '{"token":"MYTOKEN","channel":"Chanel-ID", "message": {"text":"curl", "thread_ts":"1543586718.000800"}}' https://hooks.slack.com/services/MYSLACKHOOKID

Everytime I do this, I get the response "No-text", can someone help me on the way to my goal, All i wanna do is making a respond to a message.


Solution

  • You have a couple of issues in your curl statement.

    1. Incoming webhooks do not support threads, so you need to use the chat.postMessage API method instead. As stated in the documentation:

      Incoming webhooks do not support threads. If you want your app to respond with a message in a thread, use chat.postMessage.

    2. The syntax of your JSON is not correct. there is no message property. Instead make one flat JSON array with all needed properties (except token), e.g. channel, text, thread_ts. See here for full syntax of chat.postMessage

    3. When posting as JSON you must include your token in the authorization header, not in the body of your request. As explained here in more detail.

    4. Last, but not least I would recommend to specify the charset or you will get a warning.

    The complete curl looks like this:

    curl https://slack.com/api/chat.postMessage -X POST -H 'Content-type: application/json; charset=utf-8' -H "Authorization: Bearer TOKEN" --data '{"channel":"CHANNEL-ID", "text":"curl", "thread_ts":"THREAD-TS"}'