Send Messages to Gitter Rooms Using REST API v1
Use Gitter's REST API v1 to post messages to GitHub-linked rooms, with token setup, room lookup, and delivery checks.
10 Sept 2025, 11:29 UTC

You need to post automated notifications to a Gitter chat room without opening the browser. Gitter rooms can be linked to GitHub repositories, and Gitter exposes a REST API v1 endpoint for sending messages. The useful takeaway is to authenticate with a personal access token, look up the room ID through the rooms list endpoint, then POST a JSON message body to the room's chat endpoint—while treating the token as a secret and verifying delivery before relying on the integration.
Desired outcome
A script or application can send a text message to a specific Gitter room and receive a successful HTTP response. The message appears in the room's chat history in the Gitter UI.
Prerequisites
- A Gitter account with access to the target room.
- A Gitter room you can post to, optionally linked to a GitHub repository.
- Ability to run
curlfrom a terminal or use an HTTP client in your application. - Network access to
api.gitter.im.
Version assumption: This guide targets Gitter REST API v1. Gitter's operational status and API availability have changed; verify the service is reachable before production use.
Step 1: Create a personal access token
Gitter authenticates API requests with a personal access token sent as a Bearer token in the Authorization header. A personal access token is a long-lived credential tied to your user account.
- Open Gitter account settings in a browser.
- Create a new personal access token.
- Copy the token and store it immediately.
- Store it in an environment variable or secrets manager. Do not commit it to version control.
Risk: If the token is leaked, anyone with it can act as your Gitter user. Rotate it immediately if exposed.
Step 2: List rooms and confirm the room ID
You need the internal room ID, not the human-readable room name.
Where to run: Local terminal or CI environment with network access.
Permissions: No special system permissions. You need the token and network access.
curl -s -H "Authorization: Bearer $GITTER_TOKEN" \
https://api.gitter.im/v1/rooms
Expected check: The response is a JSON array. Each object includes an id field and a name or uri field. Find the object matching your target room and copy its id value into $ROOM_ID.
Diagnostic decision:
- If the response is empty, the token may lack access to any rooms, or the room may not be linked to your account.
- If the response is 401, the token is invalid or expired.
- If the response is 429, you have hit rate limiting. Wait and retry with backoff.
Risk: Parsing the wrong room ID sends messages to the wrong chat.
Step 3: Send a chat message
Send a POST request to the room's chat messages endpoint. The body must be valid JSON with a text field. Markdown in the text field is typically rendered by Gitter.
Where to run: Same terminal or application host.
Permissions: Same as above.
curl -s -X POST https://api.gitter.im/v1/rooms/$ROOM_ID/chatMessages \
-H "Authorization: Bearer $GITTER_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Deployment complete for main branch."}'
Expected checks:
- HTTP 200 or 201 indicates the message was accepted.
- The response body includes message details such as an
idand sent timestamp. - Open the Gitter room in a browser and confirm the message appears in the chat stream.
Risks:
- Invalid JSON or unescaped special characters in
textreturns HTTP 400. - HTTP 429 means rate limiting; implement exponential backoff and retry.
- HTTP 403 means the token does not have permission to post in that room.
Example shell script
#!/usr/bin/env bash
set -euo pipefail
GITTER_TOKEN="${GITTER_TOKEN:?Set GITTER_TOKEN}"
ROOM_ID="${ROOM_ID:?Set ROOM_ID}"
MESSAGE="${1:?Provide a message}"
response=$(curl -s -w "\n%{http_code}" -X POST \
"https://api.gitter.im/v1/rooms/${ROOM_ID}/chatMessages" \
-H "Authorization: Bearer ${GITTER_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"text\": \"${MESSAGE}\"}")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [[ "$http_code" != "200" && "$http_code" != "201" ]]; then
echo "Message failed with HTTP $http_code" >&2
echo "$body" >&2
exit 1
fi
echo "Message accepted: $body"
Note: This example interpolates the message directly into JSON. In production, use a JSON encoder to escape user-supplied text and avoid malformed payloads.
Expected checks summary
| Check | Command or location | Success signal |
|---|---|---|
| Rooms list | curl ... /v1/rooms | Target room id present in JSON array |
| Message POST | curl ... /v1/rooms/{id}/chatMessages | HTTP 200/201 and message visible in Gitter UI |
| Token status | Gitter account settings | Token active and not revoked |
Recovery options
- Wrong room ID: Re-run the rooms list endpoint and verify the
nameorurimatches your target. - 401 Unauthorized: Generate a new personal access token and update
$GITTER_TOKEN. - 429 Too Many Requests: Pause requests, honor
Retry-Afterif present, and use exponential backoff. - Message posted to the wrong room: Delete the message manually in the Gitter UI if your account has permission, or post a correction. The API does not provide a guaranteed undo for sent messages.
Revoke the verification token
After testing, revoke the token in Gitter account settings to limit exposure. If you continue using the integration, rotate tokens on a schedule and store them in a secrets store rather than in scripts.
Limitations
- Gitter's service availability and API behavior are not guaranteed; verify
api.gitter.imis active before production use. - This guide does not cover webhooks, file uploads, or rich message formatting beyond text and markdown.
- Rate limits are not published in detail here; monitor for 429 responses.
Practical way to check the result
Open the target Gitter room in a browser after the POST and confirm the message text appears with the expected sender and timestamp.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.