# How To Add User With Extension From Node.js Back-End?

**URL:** <https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460>\
**Category:** English\
**Created:** [June 24, 2020, 5:23pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460 "2020-06-24T17:23:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephanoparaskeva](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@stephanoparaskeva](https://wazo-platform.discourse.group/u/stephanoparaskeva)\
**Post date:** [June 24, 2020, 5:23pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/1 "2020-06-24T17:23:08Z")

</div>

- Need to add/register user from Node.js
- Need to give user a specific ID
- Need to select _protocol_ and _extension_ all in 1 go.

## Example

```auto
export const registerAndCreateUser = async (
  res: Response,
  data: UserAuthData
) => {
  const { password, passwordConfirmation } = data;
  if (password !== passwordConfirmation) {
    throw createHttpError(400, 'Passwords do not match');
  }
  try {
    const passwordHash = await hashPassword(password);
    const user = await userRepo().save({ ...data, password: passwordHash });
    const returnedUser = omit(user, ['password', 'passwordConfirmation']);

    const WazoRegisterResponse = await axios({
      method: 'post',
      url: 'https://wazo.example.com:443/api/auth/0.1/users',
      data: {
        context: 'DefaultContext',
        extension: '1000003',
        protocol: 'Webrtc',
        email_address: returnedUser.email,
        username: returnedUser.id,
        firstname: returnedUser.firstname,
        lastname: returnedUser.lastname,
        password,
      },
    });

    return { ...returnedUser, ...WazoRegisterResponse.data }
  } catch (err) {
    throw isDuplicateKeyErr(err) ? createHttpError(403, { err }) : err;
  }
};

```

The reason I need to do this:  
Add user to Wazo for calling on app registration to fit the current flow of my app via the back-end.

**How does one do this?**

Ps. Thank you Wazo! 😃

---

<div class="post-metadata">

**Author:** ![quintana](https://yyz2.discourse-cdn.com/free1/user_avatar/wazo-platform.discourse.group/quintana/32/916_2.png) [@quintana](https://wazo-platform.discourse.group/u/quintana)\
**Post date:** [June 24, 2020, 5:39pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/2 "2020-06-24T17:39:59Z")

</div>

Have you check the API documentation?  
If you want we have a JS SDK, contribution is welcome 🙂

---

<div class="post-metadata">

**Author:** ![stephanoparaskeva](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@stephanoparaskeva](https://wazo-platform.discourse.group/u/stephanoparaskeva)\
**Post date:** [June 24, 2020, 5:48pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/3 "2020-06-24T17:48:42Z")

</div>

I read through the swagger endpoints and looked through wazo\_ui repo to see how it is doing this, when you add a user, but could not figure out how to do this in Node.js, just need to add a user with Context and Extension

---

<div class="post-metadata">

**Author:** ![quintana](https://yyz2.discourse-cdn.com/free1/user_avatar/wazo-platform.discourse.group/quintana/32/916_2.png) [@quintana](https://wazo-platform.discourse.group/u/quintana)\
**Post date:** [June 24, 2020, 5:50pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/4 "2020-06-24T17:50:59Z")

</div>

Not sure to understand, but this is exactly the same as other language, just using the REST API.

---

<div class="post-metadata">

**Author:** ![stephanoparaskeva](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@stephanoparaskeva](https://wazo-platform.discourse.group/u/stephanoparaskeva)\
**Post date:** [June 24, 2020, 5:52pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/5 "2020-06-24T17:52:34Z")

</div>

Yes, the same but how do you do this specifically, what is the URL and what is the Payload, and what is the Headers?

Eg this does not work

```auto
     {
      method: 'post',
      url: 'https://wazo.example.com:443/api/auth/0.1/users',
      data: {
        context: 'DefaultContext',
        extension: '1000003',
        protocol: 'Webrtc',
        email_address: returnedUser.email,
        username: returnedUser.id,
        firstname: returnedUser.firstname,
        lastname: returnedUser.lastname,
        password,
      },
     headers: {}
    }

```

---

<div class="post-metadata">

**Author:** ![quintana](https://yyz2.discourse-cdn.com/free1/user_avatar/wazo-platform.discourse.group/quintana/32/916_2.png) [@quintana](https://wazo-platform.discourse.group/u/quintana)\
**Post date:** [June 24, 2020, 5:53pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/6 "2020-06-24T17:53:49Z")

</div>

That my point, check the swagger spec for the documentation.

---

<div class="post-metadata">

**Author:** ![quintana](https://yyz2.discourse-cdn.com/free1/user_avatar/wazo-platform.discourse.group/quintana/32/916_2.png) [@quintana](https://wazo-platform.discourse.group/u/quintana)\
**Post date:** [June 24, 2020, 5:55pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/7 "2020-06-24T17:55:53Z")

</div>

The best will be to update our SDK here: [https://github.com/wazo-platform/wazo-js-sdk/blob/master/src/api/confd.js](https://github.com/wazo-platform/wazo-js-sdk/blob/master/src/api/confd.js)

---

<div class="post-metadata">

**Author:** ![stephanoparaskeva](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@stephanoparaskeva](https://wazo-platform.discourse.group/u/stephanoparaskeva)\
**Post date:** [June 24, 2020, 5:56pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/8 "2020-06-24T17:56:22Z")

</div>

Oh, I have. I cannot find where you add Extension and Context. This is the Swagger spec:

 ![Screenshot 2020-06-24 at 18.54.25](https://global.discourse-cdn.com/free1/uploads/wazo_platform/original/1X/bfa04c8baaa3be1f39bd4812448cba995bba05b7.png)

It does not mention Context or Extension or Protocol

And It does not say Headers

So my response is unauthorized:

 ![Screenshot 2020-06-24 at 18.55.45](https://global.discourse-cdn.com/free1/uploads/wazo_platform/original/1X/13736b86bbdd2340ee26de10664589e1472f1b6a.png)

---

<div class="post-metadata">

**Author:** ![quintana](https://yyz2.discourse-cdn.com/free1/user_avatar/wazo-platform.discourse.group/quintana/32/916_2.png) [@quintana](https://wazo-platform.discourse.group/u/quintana)\
**Post date:** [June 24, 2020, 5:59pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/9 "2020-06-24T17:59:08Z")

</div>

This is an association. We don’t have one API to do that for the moment, we have completely separated all objects. User, extensions, lines, voicemail etc … So you need to create them and associate it with the API.

---

<div class="post-metadata">

**Author:** ![stephanoparaskeva](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@stephanoparaskeva](https://wazo-platform.discourse.group/u/stephanoparaskeva)\
**Post date:** [June 24, 2020, 10:49pm UTC](https://wazo-platform.discourse.group/t/how-to-add-user-with-extension-from-node-js-back-end/460/10 "2020-06-24T22:49:58Z")

</div>

I understand now.

But can you show a way to do this _with_ the separated objects?

I understand each part is separated and it’s possible to do, when you use different methods together. But I don’t quite understand how to do it programmatically. What methods/code do I need, to do these things together:

- Register user (email, username, id, name, lastname)
- Add extension (eg “111232”)
- Add protocol (eg “Webrtc”)
- Add Context (eg “DefaultContext”)

And do this in Node.js?

Please can you explain, or give an example, as it would greatly help me build my application! 😃

Ps I don’t see the functionality:

 ![Screenshot 2020-06-24 at 23.50.56](https://global.discourse-cdn.com/free1/uploads/wazo_platform/original/1X/411e4c1beba93f9f59a74f63af63d41d7d1e65a4.png)

But maybe I can do this with a few HTTP requests, but I can’t work out which and their headers.
