[[reference-security-put_role_mapping]]

////////
===========================================================================================================================
||                                                                                                                       ||
||                                                                                                                       ||
||                                                                                                                       ||
||        ██████╗ ███████╗ █████╗ ██████╗ ███╗   ███╗███████╗                                                            ||
||        ██╔══██╗██╔════╝██╔══██╗██╔══██╗████╗ ████║██╔════╝                                                            ||
||        ██████╔╝█████╗  ███████║██║  ██║██╔████╔██║█████╗                                                              ||
||        ██╔══██╗██╔══╝  ██╔══██║██║  ██║██║╚██╔╝██║██╔══╝                                                              ||
||        ██║  ██║███████╗██║  ██║██████╔╝██║ ╚═╝ ██║███████╗                                                            ||
||        ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚══════╝                                                            ||
||                                                                                                                       ||
||                                                                                                                       ||
||    This file is autogenerated, DO NOT send pull requests that changes this file directly.                             ||
||    You should update the script that does the generation, which can be found in:                                      ||
||    https://github.com/elastic/elastic-client-generator-js                                                             ||
||                                                                                                                       ||
||    You can run the script with the following command:                                                                 ||
||       npm run elasticsearch -- --version <version>                                                                    ||
||                                                                                                                       ||
||                                                                                                                       ||
||                                                                                                                       ||
===========================================================================================================================
////////

[discrete]
[[client.security.putRoleMapping]]
=== client.security.putRoleMapping

Create or update role mappings. Role mappings define which roles are assigned to each user. Each mapping has rules that identify users and a list of roles that are granted to those users. The role mapping APIs are generally the preferred way to manage role mappings rather than using role mapping files. The create or update role mappings API cannot update role mappings that are defined in role mapping files. This API does not create roles. Rather, it maps users to existing roles. Roles can be created by using the create or update roles API or roles files.

{ref}/security-api-put-role-mapping.html[{es} documentation]

[discrete]
==== Function signature

[source,ts]
----
(SecurityPutRoleMappingRequest, options?): Promise<SecurityPutRoleMappingResponse>
----

[discrete]
==== Request

[pass]
++++
<pre>
++++
interface SecurityPutRoleMappingRequest extends <<RequestBase>> {
  name: <<Name>>
  refresh?: <<Refresh>>
  enabled?: boolean
  metadata?: <<Metadata>>
  roles?: string[]
  role_templates?: <<SecurityRoleTemplate>>[]
  rules?: <<SecurityRoleMappingRule>>
  run_as?: string[]
}

[pass]
++++
</pre>
++++
[discrete]
==== Response

[pass]
++++
<pre>
++++
interface SecurityPutRoleMappingResponse {
  created?: boolean
  role_mapping: <<SecurityCreatedStatus>>
}

[pass]
++++
</pre>
++++
