Maton

Zulip

Access the Zulip API with managed authentication, on Zulip Cloud or a self-hosted server. Read users, channels, topics, and messages; send, edit, and delete messages, add reactions, and manage channel subscriptions. All access runs through the Maton gateway and the maton CLI.

Permissions

Suggested read access

In the Console, Read limits the connection to these 43 read-only endpoints, plus deny rules for any write endpoint a broader rule would otherwise match. Endpoints Maton has found to return credentials, start jobs, or spend credits are left out; a few reads that can change state or return a secret depending on their parameters stay in, and their descriptions say how. It is a suggestion: the saved rules are exactly the ones you see, and you can change them with Custom. See Access policy.

Reference

Paths start with api/v1/: https://yourorg.zulipchat.com/api/v1/users/me becomes /zulip/api/v1/users/me.

Connect with maton connection create zulip; the Zulip connection guide shows where to find the Zulip URL, email and API key, yours or a Generic bot's.

Users

Get the Current User

maton api '/zulip/api/v1/users/me'

Response:

{
  "result": "success",
  "msg": "",
  "user_id": 5,
  "email": "user@example.com",
  "delivery_email": "user@example.com",
  "full_name": "Ada Lovelace",
  "role": 400,
  "is_bot": false,
  "is_active": true
}

role is 100 owner, 200 administrator, 300 moderator, 400 member, 600 guest.

List and Get Users

maton api '/zulip/api/v1/users'
maton api '/zulip/api/v1/users/{user_id}'
maton api '/zulip/api/v1/users/user@example.com'

Channels

List Channels and Topics

maton api '/zulip/api/v1/streams'
maton api '/zulip/api/v1/users/me/subscriptions'
maton api '/zulip/api/v1/get_stream_id?stream=general'
maton api '/zulip/api/v1/users/me/{stream_id}/topics'

Response (api/v1/streams):

{
  "result": "success",
  "msg": "",
  "streams": [
    {"stream_id": 1, "name": "general", "description": "Everyone is added to this channel.", "invite_only": false, "is_archived": false, "subscriber_count": 10}
  ]
}

api/v1/streams returns the channels you can access, api/v1/users/me/subscriptions those you're subscribed to, and get_stream_id a channel's ID from its name.

Subscribe to a Channel

maton api '/zulip/api/v1/users/me/subscriptions' -X POST -H 'Content-Type: application/x-www-form-urlencoded' --input - <<'BODY'
subscriptions=[{"name":"general"}]
BODY

A channel named here that doesn't exist is created. DELETE api/v1/users/me/subscriptions with subscriptions as a JSON list of names unsubscribes.

Messages

Get Messages

maton api '/zulip/api/v1/messages?anchor=newest&num_before=20&num_after=0&apply_markdown=false'
maton api '/zulip/api/v1/messages' -X GET -f anchor=newest -f num_before=20 -f num_after=0 \
  -f 'narrow=[{"operator":"channel","operand":"general"},{"operator":"topic","operand":"standup"}]'

Response:

{
  "result": "success",
  "msg": "",
  "anchor": 21,
  "found_newest": true,
  "messages": [
    {"id": 21, "type": "stream", "stream_id": 1, "display_recipient": "general", "subject": "standup", "sender_id": 4, "sender_full_name": "Ada Lovelace", "content": "Shipping today.", "timestamp": 1764000000, "flags": ["read"]}
  ]
}

anchor is a message ID, newest, oldest, or first_unread; num_before and num_after count messages on each side of it (up to 5,000). narrow operators include channel, topic, sender, dm, is (unread, starred, mentioned), has, and search. Without a narrow, messages come from your combined feed, including direct messages. A message's topic is subject.

Send a Message

maton api '/zulip/api/v1/messages' -X POST -H 'Content-Type: application/x-www-form-urlencoded' --input - <<'BODY'
type=channel&to=general&topic=standup&content=Shipping%20today.
BODY
maton api '/zulip/api/v1/messages' -X POST -H 'Content-Type: application/x-www-form-urlencoded' --input - <<'BODY'
type=direct&to=[12,34]&content=Can%20you%20review%20this%3F
BODY

Response:

{"result": "success", "msg": "", "id": 42}

For a channel message, to is the channel name or ID and topic is required; for a direct message, to is a JSON list of user IDs. Servers older than Zulip 9.0 take type=stream instead of channel.

Edit or Delete a Message

maton api '/zulip/api/v1/messages/{message_id}' -X PATCH -H 'Content-Type: application/x-www-form-urlencoded' --input - <<'BODY'
content=Shipping%20tomorrow.
BODY
maton api '/zulip/api/v1/messages/{message_id}' -X DELETE

PATCH changes content, or moves messages with topic (and propagate_mode) or stream_id. The organization's settings decide who may edit and delete. Deletion is permanent.

Reactions and Read State

maton api '/zulip/api/v1/messages/{message_id}/reactions' -X POST -H 'Content-Type: application/x-www-form-urlencoded' --input - <<'BODY'
emoji_name=thumbs_up
BODY
maton api '/zulip/api/v1/messages/flags' -X POST -H 'Content-Type: application/x-www-form-urlencoded' --input - <<'BODY'
messages=[21,42]&op=add&flag=read
BODY

Server Settings

maton api '/zulip/api/v1/server_settings'

Returns the server's zulip_version, zulip_feature_level, realm_name, and realm_url. The feature level tells which parameters an older self-hosted server supports.

Notes

  • Request bodies are form-encoded (application/x-www-form-urlencoded). Zulip ignores a JSON body and answers 400 Missing '...' argument; list or object parameters are JSON strings inside the form, such as to=[12,34]. Zulip's API calls channels "streams".
  • Permissions: the connection acts with the full permissions of its user or bot; Zulip has no scopes.
  • Errors are JSON: {"result": "error", "msg": "...", "code": "..."}. 401 Invalid API key or Malformed API key (code UNAUTHORIZED) means a wrong key or email; 400 a missing or invalid argument; 403 the user may not do that.
  • Host errors come from Maton with 400: the Zulip URL doesn't resolve or resolves to a private address.
  • Rate limits are per user. A 429 (code RATE_LIMIT_HIT) comes with Retry-After, and responses carry X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset.
  • Timestamps are Unix seconds.
  • Real-time event queues (api/v1/register, api/v1/events) and file uploads aren't covered here.

Resources

On this page