# Older user mappings are getting wiped out on using API to add new role mappings

**URL:** <https://forum.opensearch.org/t/older-user-mappings-are-getting-wiped-out-on-using-api-to-add-new-role-mappings/12629>\
**Category:** Security\
**Tags:** security-issue\
**Created:** [February 24, 2023, 8:10am UTC](https://forum.opensearch.org/t/older-user-mappings-are-getting-wiped-out-on-using-api-to-add-new-role-mappings/12629 "2023-02-24T08:10:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhtbansal](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rhtbansal](https://forum.opensearch.org/u/rhtbansal)\
**Post date:** [February 24, 2023, 8:10am UTC](https://forum.opensearch.org/t/older-user-mappings-are-getting-wiped-out-on-using-api-to-add-new-role-mappings/12629/1 "2023-02-24T08:10:12Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):

when adding role mappings to the opensearch via API previous role maping are gettimg wiped out

we have tried using bot the below manetioned API.  
if we have to append the previous list of users with a new user, all the previous role mapping(user) mapped to the role are getting removed.

PUT \_plugins/\_security/api/rolesmapping/  
PATCH \_plugins/\_security/api/rolesmapping/  
[  
{  
“op”: “add”, “path”: “/users”, “value”: [“mynewuser”]  
}]

**Describe the issue** :

**Configuration** :

**Relevant Logs or Screenshots** :

---

<div class="post-metadata">

**Author:** ![kris](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/kris/32/2208_2.png) [@kris](https://forum.opensearch.org/u/kris)\
**Post date:** [February 24, 2023, 5:56pm UTC](https://forum.opensearch.org/t/older-user-mappings-are-getting-wiped-out-on-using-api-to-add-new-role-mappings/12629/2 "2023-02-24T17:56:47Z")

</div>

Hello @rhtbansal - what version is the happening on?

---

<div class="post-metadata">

**Author:** ![rhtbansal](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rhtbansal](https://forum.opensearch.org/u/rhtbansal)\
**Post date:** [February 24, 2023, 6:11pm UTC](https://forum.opensearch.org/t/older-user-mappings-are-getting-wiped-out-on-using-api-to-add-new-role-mappings/12629/3 "2023-02-24T18:11:07Z")

</div>

We are using 2.2 version of opensearch

---

<div class="post-metadata">

**Author:** ![pablo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/pablo/32/10363_2.png) [@pablo](https://forum.opensearch.org/u/pablo)\
**Post date:** [February 26, 2023, 5:32pm UTC](https://forum.opensearch.org/t/older-user-mappings-are-getting-wiped-out-on-using-api-to-add-new-role-mappings/12629/4 "2023-02-26T17:32:37Z")

</div>

@rhtbansal Your API works as expected as you’re sending an array instead of a single element.

Try the below if you’d like to add a user to the end of the array.

```auto
curl --insecure -H "Content-Type: application/json" -u admin:admin -XPATCH https://localhost:9200/_plugins/_security/api/rolesmapping/<role_name> -d ' 
 
[{ 
 
  "op":"add", "path":"/users/-", "value": "<user_name>" 
 
}] 
 
' 

```

Also, you can add the user in the specific place of the user’s array.

```auto
curl --insecure -H "Content-Type: application/json" -u admin:admin -XPATCH https://localhost:9200/_plugins/_security/api/rolesmapping/<role_name> -d ' 
 
[{ 
 
  "op":"add", "path":"/users/0", "value": "<user_name>" 
 
}] 
 
' 

```

---

<div class="post-metadata">

**Author:** ![rhtbansal](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rhtbansal](https://forum.opensearch.org/u/rhtbansal)\
**Post date:** [February 27, 2023, 2:21pm UTC](https://forum.opensearch.org/t/older-user-mappings-are-getting-wiped-out-on-using-api-to-add-new-role-mappings/12629/5 "2023-02-27T14:21:24Z")

</div>

It worked, thanks for your help.
