# Add a user to role-mapping

**URL:** <https://forum.opensearch.org/t/add-a-user-to-role-mapping/3167>\
**Category:** Open Source Elasticsearch and Kibana\
**Created:** [June 24, 2020, 3:26pm UTC](https://forum.opensearch.org/t/add-a-user-to-role-mapping/3167 "2020-06-24T15:26:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jathin12](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jathin12](https://forum.opensearch.org/u/jathin12)\
**Post date:** [June 24, 2020, 3:26pm UTC](https://forum.opensearch.org/t/add-a-user-to-role-mapping/3167/1 "2020-06-24T15:26:56Z")

</div>

Is there any api to update role mapping user such that it appends to the array of users. till now i can only find a api that would patch the whole array.

[https://opendistro.github.io/for-elasticsearch-docs/docs/security-access-control/api/#patch-role-mapping](https://opendistro.github.io/for-elasticsearch-docs/docs/security-access-control/api/#patch-role-mapping)

````auto
PATCH _opendistro/_security/api/rolesmapping/<role>
[
  {
    "op": "replace", "path": "/users", "value": ["userA", "userB", "userC"]
  }
]```

so at some point later i need to add userD. i need to get the existing list and add userD. 
i was expecting a idempotent way to add a user to rolemapping such that i do not have to care about the existing list that has the role mapping.
````

---

<div class="post-metadata">

**Author:** ![helmanofer](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/helmanofer/32/671_2.png) [@helmanofer](https://forum.opensearch.org/u/helmanofer)\
**Post date:** [June 27, 2020, 4:34pm UTC](https://forum.opensearch.org/t/add-a-user-to-role-mapping/3167/2 "2020-06-27T16:34:07Z")

</div>

Hi,

I am also trying to add mappings, I’ve tried:

```auto
PATCH _opendistro/_security/api/rolesmapping/<role>
[
  {
    "op": "add", "path": "/users", "value": ["userD"]
  }
] 

```

Unfortunately it doesn’t add userD, but replaces the whole mappings with userD

---

<div class="post-metadata">

**Author:** ![Mer](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@Mer](https://forum.opensearch.org/u/Mer)\
**Post date:** [July 27, 2020, 12:57pm UTC](https://forum.opensearch.org/t/add-a-user-to-role-mapping/3167/3 "2020-07-27T12:57:15Z")

</div>

Hello  
Actually you can do sth like this:

[

```
{

    "op": "add",

    "path": "/users/-",

    "value": "userD"

    

}

```

]

This will add it to the existant map.

---

<div class="post-metadata">

**Author:** ![aman](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@aman](https://forum.opensearch.org/u/aman)\
**Post date:** [September 29, 2021, 11:48am UTC](https://forum.opensearch.org/t/add-a-user-to-role-mapping/3167/4 "2021-09-29T11:48:05Z")

</div>

While running

PATCH \_opendistro/\_security/api/rolesmapping/  
[  
{  
“op”: “replace”, “path”: “/users”, “value”: [“myuser”]  
}  
]

the result returned

{“statusCode”:400,“error”:“Bad Request”,“message”:“[request query.method]: Method must be one of, case insensitive [‘HEAD’, ‘GET’, ‘POST’, ‘PUT’, ‘DELETE’]. Received ‘PATCH’.”}

Maybe Patch is not accepted.

Need to know how to update the role without over writing the previous values
