# How to create a user in rancher api?

**URL:** <https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888>\
**Category:** Rancher 1.x\
**Created:** [May 24, 2016, 9:26am UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888 "2016-05-24T09:26:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adaikal\_Raj](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@Adaikal\_Raj](https://forums.suse.com/u/Adaikal_Raj)\
**Post date:** [May 24, 2016, 9:26am UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/1 "2016-05-24T09:26:20Z")

</div>

Hi,

I have been trying to create a user in rancher api and i have only partially succeeded.

With the below api call I’m able to create a user named “testuser3”

curl -u “${CATTLE\_ACCESS\_KEY}:${CATTLE\_SECRET\_KEY}”   
-X POST   
-H ‘Accept: application/json’   
-H ‘Content-Type: application/json’   
-d ‘{“description”:“test account”, “kind”:“user”, “name”:“testuser3”}’   
‘[http://192.168.54.207/v1/accounts](http://192.168.54.207/v1/accounts)’

But the problem with above call is, I’m able to create user but there is no username created for the user as you could see in the attachment.

 ![](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/f/f34e76b302c99c3b16524f0912f48550544c5382.PNG)

Few topics in the forum led to /v1/localauthconfigs but that is for enabling localauth in rancher I believe.

I have Local auth enabled in rancher.

Thank you.

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [May 24, 2016, 5:04pm UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/2 "2016-05-24T17:04:02Z")

</div>

It’s two separate requests, one to create the account and another to assign the password. In the response to the first one (what you have is fine) you’ll get the account id, then

```auto
curl -X POST ... \
  -d '{"publicValue":"yourusername","secretValue":"yourpassword","accountId":"1a114"}' \
  http://192.168.54.207/v1/password

```

---

<div class="post-metadata">

**Author:** ![Adaikal\_Raj](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@Adaikal\_Raj](https://forums.suse.com/u/Adaikal_Raj)\
**Post date:** [May 25, 2016, 4:54am UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/3 "2016-05-25T04:54:43Z")

</div>

Thank you Vincent, it’s working.

---

<div class="post-metadata">

**Author:** ![fuhbar](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/fuhbar/32/1600_2.png) [@fuhbar](https://forums.suse.com/u/fuhbar)\
**Post date:** [August 16, 2016, 9:46pm UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/4 "2016-08-16T21:46:34Z")

</div>

Thanks @vincent, this has been very helpful.

I got totally confused with the different resources like `credentials`, `apiKeys`, `passwords` and `registrationTokens`.

What I’ve learned so far: Instead of interacting with the `credentials` resource API, better deal with the more specific and therefore higher level API resources mentioned above.

Am I right or still on the wrong path?

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [August 17, 2016, 12:44am UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/5 "2016-08-17T00:44:25Z")

</div>

They are “subclasses” of `credential`, so yes generally you would want to work with the specific type.

---

<div class="post-metadata">

**Author:** ![fuhbar](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/fuhbar/32/1600_2.png) [@fuhbar](https://forums.suse.com/u/fuhbar)\
**Post date:** [August 17, 2016, 10:10am UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/6 "2016-08-17T10:10:49Z")

</div>

@vincent Need to bother you with more questions regarding the semantics of user handling - need more clarification:

- **What is the meaning of the `identity` resource?** As I understood it, its the link between external auth provider like OpenLDAP or Github or whatever and the local configured accounts. So we have transitional data here which is only valid as long as an account has been authenticated via this external auth provider? I could not find any database manifestation of this resource. Where is this data maintained?

- While creating a `project` I can also feed the API with the list of members of this project. I need to specify the `role` and the `externalId`. **What is the `externalId` referring to?** With local authentication enabled, the `externalId` seems to refer the local account id, but with OpenLDAP authentication enabled the `exernalId` referring to the Distinguish Name of the user object in the LDAP tree which is only resolvable via the `identity` resource. So question is, where is this _foreign key relationship_ pointing to?

- **What are `projectmember` used for?** Naturally this thinking brought me to the `projectmember` resource. This would enable me to separate the tasks of creating an `project` and adding member to it. But if I create an `project` manually via the UI (where its called `environment`) and add member to it, they do not appear in the `projectmember` resource. What am I missing here? Is this a legacy leftover or created for future use?

Sorry for being that verbose, but I am trying to write a deployment mechanism for Ansible which deploys Rancher/Cattle with basic configuration like authentication, user handling, environment handling and agent auto-registration. And I got stuck in making sense out of my observations. My questions aim at being able to generically process these resources.

TIA

---

<div class="post-metadata">

**Author:** ![fuhbar](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/fuhbar/32/1600_2.png) [@fuhbar](https://forums.suse.com/u/fuhbar)\
**Post date:** [August 23, 2016, 10:15am UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/7 "2016-08-23T10:15:48Z")

</div>

@vincent Ok, let me condense these questions into just a single one: **How do I add project members** to already created projects under different authentication provider (local auth, LDAP) **via API**?

TIA

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [August 23, 2016, 5:47pm UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/8 "2016-08-23T17:47:27Z")

</div>

Sorry, missed this…

Identities are the way you interact with the users/groups/orgs/teams/whatever that the auth provider has available. The data comes from the auth provider and is not saved in the database (except for localauth, where we are the provider too).

externalId and externalIdType are, as far as you should be concerned, opaque strings that come from the auth provider and identify a specific resource. They’re “external”, not “foreign”, because we are not the authority for who a person is or what users are part of a group, etc. It’s pointing to an entry in the external provider, encoded in whatever way makes sense to them (for LDAP it’s the entry’s DN, for GitHub the account’s user\_id, etc)

The `members` array on a `project` is the list of identities that can use that project. To change it you use the `setmembers` action on the project. I’m guessing you’re looking at `/v1/projectMembers`, which isn’t a top-level type that should be actually visible, it’s just the input type for the `setmembers` action. If you are an admin there are a bunch of irrelevant top-level types that are shown, which will be fixed in an API v2 (along with renaming project-\>environment and environment-\>stack, and other things).

---

<div class="post-metadata">

**Author:** ![vikas027](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vikas027/32/1146_2.png) [@vikas027](https://forums.suse.com/u/vikas027)\
**Post date:** [March 23, 2017, 1:44am UTC](https://forums.suse.com/t/how-to-create-a-user-in-rancher-api/2888/9 "2017-03-23T01:44:31Z")

</div>

> [@vincent](#):
>
> curl -X POST …   
> -d ‘{“publicValue”:“yourusername”,“secretValue”:“yourpassword”,“accountId”:“1a114”}’   
> [http://192.168.54.207/v1/password](http://192.168.54.207/v1/password)

Hello @vincent,

I have noticed a weird thing (I am on v1.5.2). This command does the job but still the username doesn’t populates in the Accounts page until the user logs in once.

Cheers,  
Vikas
