Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js_examples: Migrate and test add_subscriptions example.
Kartik Srivastavadb303ccaefd1
diff --git a/templates/zerver/api/subscribe.md b/templates/zerver/api/subscribe.mdindex 587e47f9ac2..144ebfc95af 100644--- a/templates/zerver/api/subscribe.md+++ b/templates/zerver/api/subscribe.md@@ -13,36 +13,7 @@More examples and documentation can be found [here](https://github.com/zulip/zulip-js).-```js-const zulip = require('zulip-js');--// Pass the path to your zuliprc file here.-const config = {- zuliprc: 'zuliprc',-};--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` parameter, like so:- const anotherUserParams = {- subscriptions: JSON.stringify([- {'name': 'Verona'},- {'name': 'Denmark'}- ]),- principals: JSON.stringify(['[email protected]']),- };- client.users.me.subscriptions.add(anotherUserParams).then(console.log);-});-```+{generate_code_example(javascript)|/users/me/subscriptions:post|example}{tab|curl}diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.jsindex 15ffc2c2814..930c6cfb14a 100644--- a/zerver/openapi/javascript_examples.js+++ b/zerver/openapi/javascript_examples.js@@ -48,6 +48,7 @@ const ExamplesHandler = function () {await generate_validation_data(client, examples.register_queue);await generate_validation_data(client, examples.render_message);await generate_validation_data(client, examples.set_typing_status);+ await generate_validation_data(client, examples.add_subscriptions);console.log(JSON.stringify(response_data));return;@@ -228,4 +229,32 @@ add_example('set_typing_status', '/typing:post', 200, async (client) => {// {code_example|end}});+add_example('add_subscriptions', '/users/me/subscriptions:post', 200, async (client) => {+ // {code_example|start}+ // Subscribe to the streams "Verona" and "Denmark"+ const meParams = {+ subscriptions: JSON.stringify([+ {name: 'Verona'},+ {name: 'Denmark'},+ ]),+ };+ const result_1 = await client.users.me.subscriptions.add(meParams);+ // {code_example|end}++ // {code_example|start}+ // To subscribe another user to a stream, you may pass in+ // the `principals` parameter, like so:+ const user_id = 7;+ const anotherUserParams = {+ subscriptions: JSON.stringify([+ {name: 'Verona'},+ {name: 'Denmark'},+ ]),+ principals: JSON.stringify([user_id]),+ };+ const result_2 = await client.users.me.subscriptions.add(anotherUserParams);+ // {code_example|end}+ return [result_1, result_2];+});+main();