POST https://z.u1v.ru/api/v1/users/me/subscriptions
Subscribe one or more users to one or more channels.
If any of the specified channels do not exist, they are automatically
created. The initial channel settings will be determined
by the optional parameters, like invite_only, detailed below.
Note that the ability to subscribe oneself and/or other users
to a specified channel depends on the channel's permissions
settings.
Changes: Before Zulip 10.0 (feature level 362),
subscriptions in archived channels could not be modified.
Before Zulip 10.0 (feature level 357), the
can_subscribe_group permission, which allows members of the
group to subscribe themselves to the channel, did not exist.
Before Zulip 10.0 (feature level 349), a user cannot subscribe
other users to a private channel without being subscribed
to that channel themselves. Now, If a user is part of
can_add_subscribers_group, they can subscribe themselves or other
users to a private channel without being subscribed to that channel.
Removed stream_post_policy and is_announcement_only
parameters in Zulip 10.0 (feature level 333), as permission to post
in the channel is now controlled by can_send_message_group.
Before Zulip 8.0 (feature level 208), if a user specified by the
principals parameter was a deactivated user,
or did not exist, then an HTTP status code of 403 was returned with
code: "UNAUTHORIZED_PRINCIPAL" in the error response. As of this
feature level, an HTTP status code of 400 is returned with
code: "BAD_REQUEST" in the error response for these cases.
Usage examples
Python
JavaScript
curl
#!/usr/bin/env python3importpero# Pass the path to your perorc file here.client=pero.Client(config_file="~/.perorc")# Create and subscribe to channel "python-test".result=client.add_subscriptions(streams=[{"name":"python-test","description":"Channel for testing Python",},],)# To subscribe other users to a channel, you may pass# the `principals` argument, like so:result=client.add_subscriptions(streams=[{"name":"python-test"},],principals=[user_id],)print(result)
More examples and documentation can be found here.
constzulipInit=require("zulip-js");// Pass the path to your perorc file here.constconfig={zuliprc:"perorc"};(async()=>{constclient=awaitzulipInit(config);// Subscribe to the channels "Verona" and "Denmark"constmeParams={subscriptions:JSON.stringify([{name:"Verona"},{name:"Denmark"}]),};console.log(awaitclient.users.me.subscriptions.add(meParams));// To subscribe another user to a channel, you may pass in// the `principals` parameter, like so:constuser_id=7;constanotherUserParams={subscriptions:JSON.stringify([{name:"Verona"},{name:"Denmark"}]),principals:JSON.stringify([user_id]),};console.log(awaitclient.users.me.subscriptions.add(anotherUserParams));})();
The -u line implements HTTP Basic authentication.
See the Authorization header documentation for how
to get those credentials for users and bots.
An array of objects containing information about the
channels that users will be subscribed to.
For each channel, there must be a key name and value
specifying the name of the channel. If a channel with that
name does not exist, then a new channel is created.
subscriptions object details:
name: stringrequired
The name of the channel.
Clients should use the max_stream_name_length returned by the
POST /register endpoint to determine
the maximum channel name length.
description: stringoptional
The description
to use for a new channel being created, in text/markdown format.
See the help center article on message
formatting
for details on Zulip-flavored Markdown.
Clients should use the max_stream_description_length returned
by the POST /register endpoint to
determine the maximum channel description length.
color: stringoptional
The hex value of the user's display color for the channel.
The server will return an error if the value is not a valid
hex color code.
This color is only applied to subscriptions that are newly
created by this request. Users who are already subscribed to
the channel, or who were subscribed to it in the past, keep
their existing display color. If this key is omitted, the
server assigns each new subscriber a display color, preferring
one that they are not already using for another channel.
Some clients compute a placeholder color when displaying the
current user's unsubscribed channels so that they don't all
show up in a list with the same color. If a client does this,
then it should pass the placeholder color here so that the
channel's color doesn't change when the current user is
subscribed.
principals(string)[] | (integer)[]optional
Example: [11]
A list of user IDs (preferred) or Zulip API email
addresses of the users to be subscribed to or unsubscribed
from the channels specified in the subscriptions parameter.
If not provided, then the requesting user/bot will be
subscribed/unsubscribed from the specified channels.
Changes: Before Zulip 3.0 (feature level 9), only the
Zulip API email address string format was supported.
authorization_errors_fatalbooleanoptional
Example: false
A boolean specifying whether authorization errors (such as when the
requesting user is not authorized to access a private channel) should be
considered fatal or not. When true, an authorization error is reported
as such. When set to false, the response will be a 200 and any channels
where the request encountered an authorization error will be listed
in the unauthorized key.
Defaults to true.
announcebooleanoptional
Example: true
If one of the channels specified did not exist previously and is thus created
by this call, this determines whether notification bot
will send an announcement about the new channel's creation.
Defaults to false.
invite_onlybooleanoptional
Example: true
As described above, this endpoint will create a new channel if passed
a channel name that doesn't already exist. This parameters and the ones
that follow are used to request an initial configuration of a created
channel; they are ignored for channels that already exist.
This parameter determines whether any newly created channels will be
private channels.
Defaults to false.
is_web_publicbooleanoptional
Example: true
This parameter determines whether any newly created channels will be
web-public channels.
Note that creating web-public channels requires the
WEB_PUBLIC_STREAMS_ENABLEDserver setting
to be enabled on the Zulip server in question, the organization
to have enabled the enable_spectator_access realm setting, and
the current use to have permission under the organization's
can_create_web_public_channel_group realm setting.
Changes: New in Zulip 5.0 (feature level 98).
Defaults to false.
is_default_streambooleanoptional
Example: true
This parameter determines whether any newly created channels will be
added as default channels for new users joining
the organization.
Changes: New in Zulip 8.0 (feature level 200). Previously, default channel status
could only be changed using the dedicated API endpoint.
Defaults to false.
history_public_to_subscribersbooleanoptional
Example: false
Whether the channel's message history should be available to
newly subscribed members, or users can only access messages
they actually received while subscribed to the channel.
Number of days that messages sent to this channel will be stored
before being automatically deleted by the message retention
policy. Two special string format
values are supported:
"realm_default": Return to the organization-level setting.
"unlimited": Retain messages forever.
Changes: Prior to Zulip 5.0 (feature level 91), retaining
messages forever was encoded using "forever" instead of
"unlimited".
New in Zulip 3.0 (feature level 17).
default_push_notificationsbooleanoptional
Example: true
Whether mobile push notifications will be enabled by default when a
user first subscribes to this channel, potentially overriding the
user's default mobile notification
setting
for channel messages.
Because this default is applied only the first time a user
subscribes, unsubscribing and resubscribing a user does not reset
their preference to this channel default.
Only organization administrators can set or modify this value.
"inherit": Messages can be sent to named topics in this channel,
and the organization-level realm_topics_policy
is used for whether messages can be sent to the empty topic in this
channel.
"allow_empty_topic": Messages can be sent to both named topics and
the empty topic in this channel.
"disable_empty_topic": Messages can be sent to named topics in this
channel, but the empty topic is disabled.
"empty_topic_only": Messages can be sent to the empty topic in this
channel, but named topics are disabled. See "general chat"
channels.
The "empty_topic_only" policy can only be set if all existing messages
in the channel are already in the empty topic.
When creating a new channel, if the topics_policy is not specified, the
"inherit" option will be set.
Changes: In Zulip 11.0 (feature level 404), the "empty_topic_only"
option was added.
New in Zulip 11.0 (feature level 392).
Must be one of: "inherit", "allow_empty_topic", "disable_empty_topic", "empty_topic_only".
can_add_subscribers_groupinteger | objectoptional
A group-setting value defining the set of users
who have permission to add subscribers to this channel.
Users who can administer the channel or have similar realm-level
permissions can add subscribers to a public channel regardless
of the value of this setting.
Users in this group need not be subscribed to a private channel to
add subscribers to it.
Note that a user must have content access
to a channel and permission to administer the channel in order to
modify this setting.
Changes: New in Zulip 10.0 (feature level 342). Previously, there was no
channel-level setting for this permission.
A group-setting value defining the set of users
who have permission to remove subscribers from this channel.
Organization administrators can unsubscribe others from a channel as though
they were in this group without being explicitly listed here.
Note that a user must have metadata access to a channel and permission
to administer the channel in order to modify this setting.
Changes: Prior to Zulip 10.0 (feature level 349), channel administrators
could not unsubscribe other users if they were not an organization
administrator or part of can_remove_subscribers_group. Realm administrators
were not allowed to unsubscribe other users from a private channel if they
were not subscribed to that channel.
Prior to Zulip 10.0 (feature level 320), this value was always the integer
ID of a system group.
Before Zulip 8.0 (feature level 197), the can_remove_subscribers_group
setting was named can_remove_subscribers_group_id.
A group-setting value defining the set of users
who have permission to administer this channel.
Organization administrators can administer every channel as though they were
in this group without being explicitly listed here.
Note that a user must have metadata access to a channel and permission
to administer the channel in order to modify this setting.
Changes: Prior to Zulip 10.0 (feature level 349) a user needed to
have content access to a channel in
order to modify it. The exception to this rule was that organization
administrators can edit channel names and descriptions without
having full access to the channel.
New in Zulip 10.0 (feature level 325). Prior to this
change, the permission to administer channels was limited to realm
administrators.
A group-setting value defining the set of users
who have permission to delete any message in the channel.
Note that a user must have content access to a
channel in order to delete any message in the channel.
Users present in the organization-level can_delete_any_message_group
setting can always delete any message in the channel if they
have content access to that channel.
Changes: New in Zulip 11.0 (feature level 407). Prior to this
change, only the users in can_delete_any_message_group were able
delete any message in the organization.
A group-setting value defining the set of users
who have permission to delete the messages that they have sent in the channel.
Note that a user must have content access to a
channel in order to delete their own message in the channel.
Users with permission to delete any message in the channel
and users present in the organization-level can_delete_own_message_group setting
can always delete their own messages in the channel if they
have content access to that channel.
Changes: New in Zulip 11.0 (feature level 407). Prior to this
change, only the users in the organization-level can_delete_any_message_group
and can_delete_own_message_group settings were able delete their own messages in
the organization.
A group-setting value defining the set of users
who have permission to move messages out of this channel.
Note that a user must have content access to a
channel in order to move messages out of the channel.
Channel administrators and users present in the organization-level
can_move_messages_between_channels_group setting can always move messages
out of the channel if they have content access to
the channel.
Changes: New in Zulip 11.0 (feature level 396). Prior to this
change, only the users in can_move_messages_between_channels_group were able
move messages between channels.
A group-setting value defining the set of users
who have permission to move messages within this channel.
Note that a user must have content access to a
channel in order to move messages within the channel.
Channel administrators and users present in the organization-level
can_move_messages_between_topics_group setting can always move messages
within the channel if they have content access to
the channel.
Changes: New in Zulip 11.0 (feature level 396). Prior to this
change, only the users in can_move_messages_between_topics_group were able
move messages between topics of a channel.
The list of IDs of individual users in the collection of users with this permission.
Changes: Prior to Zulip 10.0 (feature level 303), this list would include
deactivated users who had the permission before being deactivated.
direct_subgroups: (integer)[]
The list of IDs of the groups in the collection of users with this permission.
folder_idintegeroptional
Example: 1
This parameter adds the newly created channel to the specified
channel folder.
Changes: New in Zulip 11.0 (feature level 389).
send_new_subscription_messagesbooleanoptional
Example: true
Whether any other users newly subscribed via this request should be
sent a direct message, from Notification Bot, notifying them about their
new subscription.
No direct messages are sent for any channels that are created as part of
this request, regardless of the value of this parameter.
The server will never send direct messages when the total number of users
who were subscribed to channels in this request was more than the value
of max_bulk_subscription_messages, which is available in the POST
/register response.
Changes: Before Zulip 11.0 (feature level 397), new subscribers
were always sent a Notification Bot direct message, which was unduly
expensive when bulk-subscribing thousands of users to a channel.
Defaults to true.
Response
Return values
subscribed: object
A dictionary where the key is the ID of the user and the value
is a list of the names of the channels that user was subscribed
to as a result of the request.
Changes: Before Zulip 10.0 (feature level 289), the user
keys were Zulip API email addresses, not user ID.
{id}: (string)[]
List of the names of the channels that were subscribed
to as a result of the query.
already_subscribed: object
A dictionary where the key is the ID of the user and the value
is a list of the names of the channels that where the user was
not added as a subscriber in this request, because they were
already a subscriber.
Changes: Before Zulip 10.0 (feature level 289), the user
keys were Zulip API email addresses, not user IDs.
{id}: (string)[]
List of the names of the channels that the user is
already subscribed to.
unauthorized: (string)[]
A list of names of channels that the requesting user/bot was not
authorized to subscribe to. Only present if "authorization_errors_fatal": false.
new_subscription_messages_sent: boolean
Only present if the parameter send_new_subscription_messages
in the request was true.
Whether Notification Bot DMs in fact sent to the added
subscribers as requested by the send_new_subscription_messages
parameter. Clients may find this value useful to communicate
with users about the effect of this request.
Changes: New in Zulip 11.0 (feature level 397).
Example response(s)
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.