Send a message with durable duplicate prevention

POST https://z.u1v.ru/api/v1/messages/idempotent

Send a message using a stable client_message_id. This server extension is available when server_message_idempotency is true in the register response. The message and its receipt commit atomically.

If the response is lost after commit, repeat the same logical message with the same UUID. The saved message ID is returned; no second message or message event is created. Receipts remain valid after message deletion, so replay never resurrects a deleted message. A replay does not promise that the referenced message still exists or remains accessible.

A missing or invalid UUID returns HTTP 400. Reusing a UUID for changed message data returns HTTP 409. Do not fall back to a new UUID or the legacy endpoint after an uncertain network error.

Usage example

Generate and persist one UUID together with the message before the first request. Reuse that UUID after a network error or application restart. The UUID below is illustrative; a different logical message requires a different UUID.

The -u line implements HTTP Basic authentication. See the Authorization header documentation for how to get those credentials for users and bots.

curl -X POST https://z.u1v.ru/api/v1/messages/idempotent \
    -u EMAIL_ADDRESS:API_KEY \
    --data-urlencode type=stream \
    --data-urlencode 'to="Denmark"' \
    --data-urlencode topic=Castle \
    --data-urlencode 'content=One message, even after a lost response.' \
    --data-urlencode client_message_id=45297589-4024-4ad8-972b-bafbe4fbd102

Only use this extension when server_message_idempotency is true in the register response. Do not fall back to sending a fresh message after an uncertain result. A conflict means the UUID was reused for different message data; resolve that mismatch instead of automatically generating a new UUID.

Parameters

type string required

Example: "direct"

The type of message to be sent.

"direct" for a direct message and "stream" or "channel" for a channel message.

Changes: In Zulip 9.0 (feature level 248), "channel" was added as an additional value for this parameter to request a channel message.

In Zulip 7.0 (feature level 174), "direct" was added as the preferred way to request a direct message, deprecating the original "private". While "private" is still supported for requesting direct messages, clients are encouraged to use to the modern convention with servers that support it, because support for "private" will eventually be removed.

Must be one of: "direct", "channel", "stream", "private".


to string | integer | (string)[] | (integer)[] required

Example: [9, 10]

The channel or users receiving the message.

For channel messages, this is either the name or integer ID of the channel.

For direct messages, this is either a list containing integer user IDs or a list containing string Zulip API email addresses. The ID or email address of the user sending the message can be included in the list, but will be ignored by the server, unless the user sending the message is the only recipient of the message.

Changes: In Zulip 2.0.0, support for using user/channel IDs was added.


content string required

Example: "Hello"

The content of the message.

Clients should use the max_message_length returned by the POST /register endpoint to determine the maximum message size.


media_group object | null optional

Server extension: explicit ordered media membership. Requires a stable client_message_id equal to id. Every attachment must be accessible and linked in message content. Markdown remains the legacy fallback and caption source. Replays include membership in the conflict check. Absent for legacy messages; null clears membership on a content edit.

media_group object details:

  • version: integer required

    Schema version of the media group; currently 1.

    Must be one of: 1.

  • id: string required

    Stable group UUID matching client_message_id.

  • items: (object)[] required

    Ordered attachments in this media group.

    items object details:

    • id: string required

      UUID identifying this media item.

    • path_id: string required

      Server-side attachment path referenced in message content.

    • kind: string required

      Media kind: photo, video, or document.

      Must be one of: "photo", "video", "document".


silent boolean optional

Example: true

Sender-requested sound suppression. Visible notifications and badge updates remain eligible under recipient preferences. Requires server_silent_send_version 1 in realm state. Persist with retry intent: changing it with an existing client_message_id returns HTTP 409. Missing/false preserves the legacy normal-send contract.

Defaults to false.


client_message_id string required

Example: "45297589-4024-4ad8-972b-bafbe4fbd102"

Stable client-generated UUID identifying one logical message. This server extension is available when server_message_idempotency is true in the register response. Persist the UUID with the message before its first attempt and reuse it for retries, including after restarting the app.

The key is scoped to the organization and sender. A replay returns the saved result without creating another message; different message data with the same key returns HTTP 409. local_id and queue_id may change between retries.

Use POST /messages/idempotent when requiring this guarantee: it rejects requests without a key instead of silently sending a non-idempotent message. Other Zulip servers may ignore this parameter on the legacy /messages endpoint.


topic string optional

Example: "Castle"

The topic of the message. Only required for channel messages ("type": "stream" or "type": "channel"), ignored otherwise.

Clients should use the max_topic_length returned by the POST /register endpoint to determine the maximum topic length.

Note: When "(no topic)" or the value of realm_empty_topic_display_name found in the POST /register response is used for this parameter, it is interpreted as an empty string.

When topics are required, this parameter can't be "(no topic)", an empty string, or the value of realm_empty_topic_display_name.

Changes: Before Zulip 10.0 (feature level 370), "(no topic)" was not interpreted as an empty string.

Before Zulip 10.0 (feature level 334), empty string was not a valid topic name for channel messages.

New in Zulip 2.0.0. Previous Zulip releases encoded this as subject, which is currently a deprecated alias.


queue_id string optional

Example: "fb67bf8a-c031-47cc-84cf-ed80accacda8"

For clients supporting local echo, the event queue ID for the client.

If passed, local_id is required.

If the message is successfully sent, the server will include local_message_id in the message event that the client with this queue_id will receive.


local_id string optional

Example: "100.01"

For clients supporting local echo, a unique string-format identifier chosen freely by the client.

If passed, queue_id is required.

If the message is successfully sent, the server will pass it back to the client without inspecting it as local_message_id in the message event that the client with the above queue_id will receive.


read_by_sender boolean optional

Example: true

Whether the message should be initially marked read by its sender. If unspecified, the server uses a heuristic based on the client name.

Changes: New in Zulip 8.0 (feature level 236).


Response

Return values

  • id: integer

    The unique ID assigned to the sent message.

  • message_url: string

    A URL that links directly to the sent message within its conversation.

    For channel messages, the channel's name is included in the URL only when the sender has access to the channel's metadata. Otherwise, a URL referencing the channel by ID alone is returned, so that the channel's name is not revealed to a sender who cannot otherwise access it (such as a bot with permission to post to the channel but not to read it).

    Changes: New in Zulip 13.0 (feature level 508).

  • message_link: string

    A Markdown link to the sent message within its conversation, matching the link produced by the "Copy link to message" feature in the Zulip web app; for example, [#channel name > topic name @ 💬](message_url).

    For direct messages, and for channel messages where the channel name is omitted from message_url as described above, this is the same plain URL as message_url since there is no suitable text label for the Markdown link formatting.

    Changes: New in Zulip 13.0 (feature level 508).

  • automatic_new_visibility_policy: integer

    If the message's sender had configured their visibility policy settings to potentially automatically follow or unmute topics when sending messages, and one of these policies did in fact change the user's visibility policy for the topic where this message was sent, the new value for that user's visibility policy for the recipient topic.

    Only present if the sender's visibility was in fact changed.

    The value can be either unmuted or followed.

    Clients will also be notified about the change in policy via a user_topic event as usual. This field is intended to be used by clients to explicitly inform the user when a topic's visibility policy was changed automatically due to sending a message.

    For example, the Zulip web application uses this field to decide whether to display a warning or notice suggesting to unmute the topic after sending a message to a muted channel. Such a notice would be confusing in the event that the act of sending the message had already resulted in the user automatically unmuting or following the topic in question.

    Changes: New in Zulip 8.0 (feature level 218).

Changes: As of Zulip 7.0 (feature level 167), if any parameters sent in the request are not supported by this endpoint, a successful JSON response will include an ignored_parameters_unsupported array.

A typical successful JSON response may look like:

{
    "automatic_new_visibility_policy": 2,
    "id": 42,
    "message_link": "[#test here > test @ \ud83d\udcac](https://example.zulipchat.com/#narrow/channel/7-test-here/topic/test/near/42)",
    "message_url": "https://example.zulipchat.com/#narrow/channel/7-test-here/topic/test/near/42",
    "msg": "",
    "result": "success"
}

A typical failed JSON response for when a channel message is sent to a channel that does not exist:

{
    "code": "STREAM_DOES_NOT_EXIST",
    "msg": "Channel 'nonexistent' does not exist",
    "result": "error",
    "stream": "nonexistent"
}

A typical failed JSON response for when a direct message is sent to a user that does not exist:

{
    "code": "BAD_REQUEST",
    "msg": "Invalid email 'eeshan@zulip.com'",
    "result": "error"
}

An example JSON error response for when the message was rejected because the message contains a stream wildcard mention, but the user doesn't have permission to use such a mention in this channel as the user is not present in can_mention_many_users_group and the channel contains a large number of subscribers.

Changes: New in Zulip 8.0 (feature level 229). Previously, this error returned the "BAD_REQUEST" code.

{
    "code": "STREAM_WILDCARD_MENTION_NOT_ALLOWED",
    "msg": "You do not have permission to use channel wildcard mentions in this channel.",
    "result": "error"
}

An example JSON error response for when the message was rejected because the message contains a topic wildcard mention, but the user doesn't have permission to use such a mention in this topic as the user is not present in can_mention_many_users_group and the topic contains a large number of participants.

Changes: New in Zulip 8.0 (feature level 229). Previously, wildcard_mention_policy was not enforced for topic mentions.

{
    "code": "TOPIC_WILDCARD_MENTION_NOT_ALLOWED",
    "msg": "You do not have permission to use topic wildcard mentions in this topic.",
    "result": "error"
}

The UUID was already committed with different message data. Resolve the mismatch instead of generating a new key on retry.

{
    "code": "BAD_REQUEST",
    "msg": "client_message_id was used for a different message",
    "result": "error"
}