# Wired thing happend when create user via API

**URL:** <https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951>\
**Category:** Support\
**Created:** [December 3, 2019, 8:15am UTC](https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951 "2019-12-03T08:15:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NathanLei](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@NathanLei](https://meta.discourse.org/u/NathanLei)\
**Post date:** [December 3, 2019, 8:15am UTC](https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951/1 "2019-12-03T08:15:21Z")

</div>

When I test API users.json , I use postman to create User, it works, and activated by default, means  
`active=true` works

But when I create a user with code in node.js. same params, `active=true` don’t work anymore, But I do get a success message.. says,

> success: true,  
> active: false,

how come. I don’t even see it at backend.

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [December 3, 2019, 10:25am UTC](https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951/2 "2019-12-03T10:25:25Z")

</div>

My guess is that your node.js code is not passing the API key correctly, so you are not being allowed to override the `active` parameter. If you can share a snippet of your code here we might be able to help out.

---

<div class="post-metadata">

**Author:** ![NathanLei](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@NathanLei](https://meta.discourse.org/u/NathanLei)\
**Post date:** [December 3, 2019, 10:31am UTC](https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951/3 "2019-12-03T10:31:22Z")

</div>

Hi David, Thank you:

here is my request:

```
{
 "url": "users.json",
 "method": "post",
 "data": {
      "api_key": "57d06a163190ee90de1118ac2adbaf5eeb5aa93d4d02dbe8f5d424c388f126e294c",
      "api_username": "Nathan001",
      "name": "tokgood",
      "email": "tokgood@qq.com",
      "password": "64c6457d-b815-4e87-8ea1-e66becd710bc",
      "username": "2cx9pyCMyn",
      "active": true,
      "approved": true
 },
 "headers": {
      "common": {
           "Accept": "application/json, text/plain, */*"
      },
      "delete": {},
      "get": {},
      "head": {},
      "post": {
           "Content-Type": "application/x-www-form-urlencoded"
      },
      "put": {
           "Content-Type": "application/x-www-form-urlencoded"
      },
      "patch": {
           "Content-Type": "application/x-www-form-urlencoded"
      },
      "content-type": "multipart/form-data"
 },
 "baseURL": "https://www.tuntry.com/",
 "transformRequest": [
      null
 ],
 "transformResponse": [
      null
 ],
 "timeout": 60000,
 "xsrfCookieName": "XSRF-TOKEN",
 "xsrfHeaderName": "X-XSRF-TOKEN",
 "maxContentLength": -1
}

```

I have double-checked the API user and key, it’s correct.

I just wrapped a post request with Axios.

```
   const post = (url, data) => service.post(url, {
   api_key: Config.discourse.api_key,
   api_username: Config.discourse.api_username,
  ...data,
 }
)

```

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [December 3, 2019, 10:35am UTC](https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951/4 "2019-12-03T10:35:11Z")

</div>

I don’t know much about node, but that looks ok as far as I can see.

One thing you could try is sending the API credentials via HTTP headers, rather than parameters. Sending via parameters is deprecated, and will cause a warning in your admin panel. The header names are `Api-Key` and `Api-Username` (note hyphens, not underscores). More info [here](https://docs.discourse.org/).

---

<div class="post-metadata">

**Author:** ![NathanLei](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@NathanLei](https://meta.discourse.org/u/NathanLei)\
**Post date:** [December 3, 2019, 1:40pm UTC](https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951/5 "2019-12-03T13:40:08Z")

</div>

Great man, Yes I solved it after add `Api-Key` and `Api-Username` and add `'content-type': 'application/json',` to the header!

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [January 2, 2020, 1:49pm UTC](https://meta.discourse.org/t/wired-thing-happend-when-create-user-via-api/134951/6 "2020-01-02T13:49:32Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
