# Bulk import role mappings from one cluster to another via API

**URL:** <https://discuss.elastic.co/t/bulk-import-role-mappings-from-one-cluster-to-another-via-api/342869>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [September 12, 2023, 4:01pm UTC](https://discuss.elastic.co/t/bulk-import-role-mappings-from-one-cluster-to-another-via-api/342869 "2023-09-12T16:01:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndrewDatTeranet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewdatteranet/32/86108_2.png) [@AndrewDatTeranet](https://discuss.elastic.co/u/AndrewDatTeranet)\
**Post date:** [September 12, 2023, 4:01pm UTC](https://discuss.elastic.co/t/bulk-import-role-mappings-from-one-cluster-to-another-via-api/342869/1 "2023-09-12T16:01:41Z")

</div>

I am attempting to dump all role mappings out of one cluster into another by using the Role Mapping API. I use the generic:

```auto
GET /_security/role_mapping

```

to dump all the mappings but cannot find a way to easily bulk import as the create/update api seems to require a name like

```auto
PUT /_security/role_mapping/<namegoeshere>

```

I tried simply not putting the name in and adding the output to the input by doing:

```auto
PUT /_security/role_mapping
{
  "Example User 1": {
    "enabled": true,
    "roles": [
      "superuser"
    ],
    "rules": {
      "all": [
        {
          "field": {
            "username": "example.user1"
          }
        },
        {
          "field": {
            "realm.name": "realmnamehere"
          }
        }
      ]
    },
    "metadata": {}
  },
  "Example User 2": {
    "enabled": true,
    "roles": [
      "superuser"
    ],
    "rules": {
      "all": [
        {
          "field": {
            "realm.name": "realmnamehere"
          }
        },
        {
          "field": {
            "username": "example.user2"
          }
        }
      ]
    },
    "metadata": {}
  }
}

```

but that failed with:

```auto
{
  "error": "Incorrect HTTP method for uri [/_security/role_mapping?pretty=true] and method [PUT], allowed: [GET]",
  "status": 405
}

```

Am I missing some easy way to do this or is the only way to load this one at a time?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [September 12, 2023, 4:16pm UTC](https://discuss.elastic.co/t/bulk-import-role-mappings-from-one-cluster-to-another-via-api/342869/2 "2023-09-12T16:16:29Z")

</div>

> [@AndrewDatTeranet](#):
>
> Am I missing some easy way to do this or is the only way to load this one at a time?

The name of the role mapping is required, so you will need to load one at a time or build a custom script to automate this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 10, 2023, 4:17pm UTC](https://discuss.elastic.co/t/bulk-import-role-mappings-from-one-cluster-to-another-via-api/342869/3 "2023-10-10T16:17:27Z")

</div>

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