Send Your First Message in 5 Minutes

Prev Next

In this quickstart, you send a message to a channel with the Rocket.Chat REST API. All you need is a terminal with curl and a Rocket.Chat account.

Prerequisites

  • A Rocket.Chat workspace you can sign in to, and its URL (for example, https://chat.example.com). If you don't have one, set up a test workspace as described in Environment.

  • Your API credentials for that workspace — an auth token and user ID.

  • A channel you can post to, such as #general.

Step 1: Get your auth tokens

Obtain your authToken and userId as described in Authenticate a REST Client — log in with your username and password, or use a personal access token. You pass these two values as headers in the next step.

Step 2: Post the message

Call the Post Message endpoint, passing your tokens as headers and the target channel and message text in the body:

curl -X POST https://<your-workspace-url>/api/v1/chat.postMessage \
     -H "X-Auth-Token: your-auth-token" \
     -H "X-User-Id: your-user-id" \
     -H "Content-Type: application/json" \
     -d '{ "channel": "#general", "text": "Sample message" }'

Expected result

A successful call returns the message that was created:

{
  "ts": 1481748965123,
  "channel": "general",
  "message": {
    "alias": "",
    "msg": "This is a test!",
    "parseUrls": true,
    "groupable": false,
    "ts": "2016-12-14T20:56:05.117Z",
    "u": {
      "_id": "y65tAmHs93aDChMWu",
      "username": "graywolf336"
    },
    "rid": "GENERAL",
    "_updatedAt": "2016-12-14T20:56:05.119Z",
    "_id": "jC9chsFddTvsbFQG7"
  },
  "success": true
}

Open the channel in your workspace — your message appears immediately.

Next steps