Register an event queue

POST https://yourZulipDomain.zulipchat.com/api/v1/register

This powerful endpoint can be used to register a Zulip "event queue" (subscribed to certain types of "events", or updates to the messages and other Zulip data the current user has access to), as well as to fetch the current state of that data.

(register also powers the call_on_each_event Python API, and is intended primarily for complex applications for which the more convenient call_on_each_event API is insufficient).

This endpoint returns a queue_id and a last_event_id; these can be used in subsequent calls to the "events" endpoint to request events from the Zulip server using long-polling.

The server will queue events for up to 10 minutes of inactivity. After 10 minutes, your event queue will be garbage-collected. The server will send heartbeat events every minute, which makes it easy to implement a robust client that does not miss events unless the client loses network connectivity with the Zulip server for 10 minutes or longer.

Once the server garbage-collects your event queue, the server will return an error with a code of BAD_EVENT_QUEUE_ID if you try to fetch events from the event queue. Your software will need to handle that error condition by re-initializing itself (e.g. this is what triggers your browser reloading the Zulip webapp when your laptop comes back online after being offline for more than 10 minutes).

When prototyping with this API, we recommend first calling register with no event_types argument to see all the available data from all supported event types. Before using your client in production, you should set appropriate event_types and fetch_event_types filters so that your client only requests the data it needs. A few minutes doing this often saves 90% of the total bandwidth and other resources consumed by a client using this API.

See the events system developer documentation if you need deeper details about how the Zulip event queue system works, avoids clients needing to worry about large classes of potentially messy races, etc.

Usage examples

curl https://yourZulipDomain.zulipchat.com/api/v1/register \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY
    -d 'event_types=["message"]'
#!/usr/bin/env python3

import zulip

# Download ~/zuliprc-dev from your dev server
client = zulip.Client(config_file="~/zuliprc-dev")

# Register the queue
result = client.register(
    event_types=['messages', 'realm_emoji']
)
print(result)

More examples and documentation can be found here.

const zulip = require('zulip-js');

// Download zuliprc-dev from your dev server
const config = {
    zuliprc: 'zuliprc-dev',
};

zulip(config).then((client) => {
    // Register a queue
    const params = {
        event_types: ['message']
    };
    client.queues.register(params).then(console.log);
});

Arguments

Argument Example Required Description
apply_markdown `True` or `False` No

Set to True if you would like the content to be rendered in HTML format (by default, the API returns the raw text that the user entered)

client_gravatar `True` or `False` No

The client_gravatar field is set to True if clients can compute their own gravatars. Default is False.

event_types event_types=['message'] No

A JSON-encoded array indicating which types of events you're interested in. Values that you might find useful include:

* message (messages),
* subscription (changes in your subscriptions),
* realm_user (changes in the list of users in your realm)

If you do not specify this argument, you will receive all events, and have to filter out the events not relevant to your client in your client code. For most applications, one is only interested in messages, so one specifies: event_types=['message']

all_public_streams `True` or `False` No

Set to True if you would like to receive events that occur within all public streams. Default is None.

include_subscribers `True` or `False` No

Set to True if you would like to receive events that include the subscribers for each stream. Default is False.

fetch_event_types event_types=['message'] No

Same as the event_types argument except that the values in fetch_event_types are used to fetch initial data. If fetch_event_types is not provided, event_types is used and if event_types is not provided, this argument defaults to None.

narrow narrow=['stream', 'Denmark'] No

A JSON-encoded array of length 2 indicating the narrow for which you'd like to receive events for. For instance, to receive events for the stream Denmark, you would specify narrow=['stream', 'Denmark']. Another example is narrow=['is', 'private'] for private messages. Default is [].

Response

Return values

  • queue_id: The ID of the queue that has been allocated for your client.
  • last_event_id: The initial value of last_event_id to pass to GET /api/v1/events.

Example response

A typical successful JSON response may look like:

{
    "last_event_id": -1,
    "msg": "",
    "queue_id": "1517975029:0",
    "realm_emoji": {
        "1": {
            "author": {
                "email": "iago@zulip.com",
                "full_name": "Iago",
                "id": 5
            },
            "deactivated": false,
            "id": "1",
            "name": "green_tick",
            "source_url": "/user_avatars/1/emoji/images/1.png"
        }
    },
    "result": "success"
}