js-api: Migrate and test create-user example.

This commit is contained in:
Rohitt Vashishtha 2020-05-17 10:26:12 +00:00 committed by Tim Abbott
parent 61f6a6e9bb
commit 203b722624
2 changed files with 15 additions and 19 deletions

View File

@ -14,25 +14,8 @@
{tab|js}
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
```js
const zulip = require('zulip-js');
// The user for this zuliprc file must be an organization administrator.
const config = {
zuliprc: 'zuliprc-admin',
};
zulip(config).then((client) => {
// Create a user
const params = {
email: 'newbie@zulip.com',
password: 'temp',
full_name: 'New User',
short_name: 'newbie'
};
client.users.create(params).then(console.log);
});
```
{generate_code_example(javascript)|/users:post|example(admin_config=True)}
{tab|curl}

View File

@ -58,8 +58,21 @@ const ExamplesHandler = function () {
};
};
const {main} = ExamplesHandler();
const {main, add_example} = ExamplesHandler();
// Declare all the examples below.
add_example('create_user', '/users:post', 200, async (client) => {
// {code_example|start}
const params = {
email: 'newbie@zulip.com',
password: 'temp',
full_name: 'New User',
short_name: 'newbie',
};
return await client.users.create(params);
// {code_example|end}
});
main();