2018-01-06 23:49:14 +01:00
|
|
|
# Add subscriptions
|
|
|
|
|
|
|
|
Subscribe one or more users to one or more streams.
|
|
|
|
|
|
|
|
`POST {{ api_url }}/v1/users/me/subcriptions`
|
|
|
|
|
2018-06-26 21:33:13 +02:00
|
|
|
If any of the specified streams do not exist, they are automatically
|
|
|
|
created, and configured using the `invite_only` setting specified in
|
|
|
|
the arguments (see below).
|
|
|
|
|
2018-01-06 23:49:14 +01:00
|
|
|
## Usage examples
|
|
|
|
<div class="code-section" markdown="1">
|
|
|
|
<ul class="nav">
|
|
|
|
<li data-language="python">Python</li>
|
2018-01-13 23:12:05 +01:00
|
|
|
<li data-language="javascript">JavaScript</li>
|
2018-01-22 22:49:30 +01:00
|
|
|
<li data-language="curl">curl</li>
|
2018-01-06 23:49:14 +01:00
|
|
|
</ul>
|
|
|
|
<div class="blocks">
|
|
|
|
|
|
|
|
<div data-language="curl" markdown="1">
|
|
|
|
|
|
|
|
```
|
|
|
|
curl {{ api_url }}/v1/users/me/subscriptions \
|
|
|
|
-u BOT_EMAIL_ADDRESS:BOT_API_KEY \
|
|
|
|
-d 'subscriptions=[{"name": "Verona"}]'
|
|
|
|
```
|
|
|
|
|
|
|
|
To subscribe another user to a stream, you may pass in
|
|
|
|
the `principals` argument, like so:
|
|
|
|
|
|
|
|
```
|
|
|
|
curl {{ api_url }}/v1/users/me/subscriptions \
|
|
|
|
-u BOT_EMAIL_ADDRESS:BOT_API_KEY \
|
|
|
|
-d 'subscriptions=[{"name": "Verona"}]' \
|
|
|
|
-d 'principals=["ZOE@zulip.com"]'
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div data-language="python" markdown="1">
|
|
|
|
|
2018-02-16 04:09:21 +01:00
|
|
|
{generate_code_example(python)|add-subscriptions|example}
|
2018-01-06 23:49:14 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2018-01-13 23:12:05 +01:00
|
|
|
<div data-language="javascript" markdown="1">
|
|
|
|
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
|
|
|
|
```js
|
|
|
|
const zulip = require('zulip-js');
|
|
|
|
|
|
|
|
// Download zuliprc-dev from your dev server
|
|
|
|
const config = {
|
|
|
|
zuliprc: 'zuliprc-dev',
|
|
|
|
};
|
|
|
|
|
|
|
|
zulip(config).then((client) => {
|
|
|
|
// Subscribe to the streams "Verona" and "Denmark"
|
|
|
|
const meParams = {
|
|
|
|
subscriptions: JSON.stringify([
|
|
|
|
{'name': 'Verona'},
|
|
|
|
{'name': 'Denmark'}
|
|
|
|
]),
|
|
|
|
};
|
|
|
|
client.users.me.subscriptions.add(meParams).then(console.log);
|
|
|
|
|
|
|
|
// To subscribe another user to a stream, you may pass in
|
|
|
|
// the `principals` argument, like so:
|
|
|
|
const anotherUserParams = {
|
|
|
|
subscriptions: JSON.stringify([
|
|
|
|
{'name': 'Verona'},
|
|
|
|
{'name': 'Denmark'}
|
|
|
|
]),
|
|
|
|
principals: JSON.stringify(['ZOE@zulip.org']),
|
|
|
|
};
|
|
|
|
client.users.me.subscriptions.add(anotherUserParams).then(console.log);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
</div>
|
|
|
|
|
2018-01-06 23:49:14 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2018-01-20 22:03:05 +01:00
|
|
|
## Arguments
|
|
|
|
|
|
|
|
{generate_api_arguments_table|arguments.json|add-subscriptions.md}
|
|
|
|
|
2018-01-06 23:49:14 +01:00
|
|
|
## Response
|
|
|
|
|
|
|
|
#### Return values
|
|
|
|
|
|
|
|
* `subscribed`: A dictionary where the key is the email address of
|
|
|
|
the user/bot and the value is a list of the names of the streams
|
|
|
|
that were subscribed to as a result of the query.
|
|
|
|
|
|
|
|
* `already_subscribed`: A dictionary where the key is the email address of
|
|
|
|
the user/bot and the value is a list of the names of the streams
|
|
|
|
that the user/bot is already subscribed to.
|
|
|
|
|
|
|
|
* `unauthorized`: A list of names of streams that the requesting user/bot
|
|
|
|
was not authorized to subscribe to.
|
|
|
|
|
|
|
|
#### Example response
|
|
|
|
|
|
|
|
A typical successful JSON response may look like:
|
|
|
|
|
2018-02-06 04:17:10 +01:00
|
|
|
{generate_code_example|add-subscriptions|fixture(without_principals)}
|
2018-01-06 23:49:14 +01:00
|
|
|
|
|
|
|
A typical successful JSON response when the user is already subscribed to
|
|
|
|
the streams specified:
|
|
|
|
|
2018-02-16 22:41:29 +01:00
|
|
|
{generate_code_example|add-subscriptions|fixture(already_subscribed)}
|
2018-01-06 23:49:14 +01:00
|
|
|
|
|
|
|
A typical response for when the requesting user does not have access to
|
|
|
|
a private stream and `authorization_errors_fatal` is `True`:
|
|
|
|
|
2018-02-16 23:22:45 +01:00
|
|
|
{generate_code_example|add-subscriptions|fixture(unauthorized_errors_fatal_true)}
|
2018-01-06 23:49:14 +01:00
|
|
|
|
|
|
|
A typical response for when the requesting user does not have access to
|
|
|
|
a private stream and `authorization_errors_fatal` is `False`:
|
|
|
|
|
2018-02-16 23:22:45 +01:00
|
|
|
{generate_code_example|add-subscriptions|fixture(unauthorized_errors_fatal_false)}
|