2022-02-07 08:05:01 +08:00
|
|
|
|
[role="xpack"]
|
|
|
|
|
[[security-api-update-user-profile-data]]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
=== Update user profile data API
|
2022-02-07 08:05:01 +08:00
|
|
|
|
++++
|
|
|
|
|
<titleabbrev>Update user profile data</titleabbrev>
|
|
|
|
|
++++
|
|
|
|
|
|
2022-09-29 09:14:09 +08:00
|
|
|
|
NOTE: The user profile feature is designed only for use by {kib} and
|
|
|
|
|
Elastic’s {observability}, {ents}, and {elastic-sec} solutions. Individual
|
|
|
|
|
users and external applications should not call this API directly. Elastic reserves
|
|
|
|
|
the right to change or remove this feature in future releases without prior notice.
|
2022-03-15 08:08:25 +08:00
|
|
|
|
|
2022-02-10 07:00:16 +08:00
|
|
|
|
Updates specific data for the user profile that's associated with the specified
|
|
|
|
|
unique ID.
|
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-request]]
|
|
|
|
|
==== {api-request-title}
|
|
|
|
|
|
2022-03-15 05:25:10 +08:00
|
|
|
|
`POST /_security/profile/<uid>/_data`
|
2022-02-10 07:00:16 +08:00
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-prereqs]]
|
|
|
|
|
==== {api-prereq-title}
|
|
|
|
|
|
|
|
|
|
To use this API, you must have one of the following privileges:
|
|
|
|
|
|
|
|
|
|
* The `manage_user_profile` cluster privilege.
|
|
|
|
|
* The `update_profile_data` global privilege for the namespaces that are
|
|
|
|
|
referenced in the request.
|
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-desc]]
|
|
|
|
|
==== {api-description-title}
|
|
|
|
|
|
2022-04-14 06:47:34 +08:00
|
|
|
|
The update user profile API updates the `labels` and `data` fields of an
|
2022-02-10 07:00:16 +08:00
|
|
|
|
existing user profile document with JSON objects. New keys and their values are
|
|
|
|
|
added to the profile document, and conflicting keys are replaced by data that's
|
|
|
|
|
included in the request.
|
|
|
|
|
|
2022-04-14 06:47:34 +08:00
|
|
|
|
For both `labels` and `data`, content is namespaced by the top-level fields.
|
2022-02-10 07:00:16 +08:00
|
|
|
|
The `update_profile_data` global privilege grants privileges for updating only
|
|
|
|
|
the allowed namespaces.
|
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-path-params]]
|
|
|
|
|
==== {api-path-parms-title}
|
|
|
|
|
|
|
|
|
|
`uid`::
|
|
|
|
|
(Required, string) A unique identifier for the user profile.
|
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-query-params]]
|
|
|
|
|
==== {api-query-parms-title}
|
|
|
|
|
|
2024-04-17 20:37:07 +08:00
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=if_seq_no]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
|
2024-04-17 20:37:07 +08:00
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=if_primary_term]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
|
2024-04-17 20:37:07 +08:00
|
|
|
|
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=refresh]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
|
|
|
|
|
`uid`::
|
|
|
|
|
(Required, string) A unique identifier for the user profile.
|
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-request-body]]
|
|
|
|
|
==== {api-request-body-title}
|
|
|
|
|
|
2022-04-14 06:47:34 +08:00
|
|
|
|
`labels`::
|
2022-02-10 07:00:16 +08:00
|
|
|
|
(Required*, object)
|
|
|
|
|
Searchable data that you want to associate with the user profile.
|
2022-04-14 06:47:34 +08:00
|
|
|
|
This field supports a nested data structure. Within the `labels` object,
|
2022-02-10 07:00:16 +08:00
|
|
|
|
top-level keys cannot begin with an underscore (`_`) or contain a period (`.`).
|
|
|
|
|
|
|
|
|
|
`data`::
|
|
|
|
|
(Required*, object)
|
|
|
|
|
Non-searchable data that you want to associate with the user profile.
|
|
|
|
|
This field supports a nested data structure. Within the `data` object, top-level
|
|
|
|
|
keys cannot begin with an underscore (`_`) or contain a period (`.`)
|
2022-03-15 05:25:10 +08:00
|
|
|
|
The `data` object is not searchable, but can be retrieved with the
|
2022-02-10 07:00:16 +08:00
|
|
|
|
<<security-api-get-user-profile,Get user profile API>>.
|
|
|
|
|
|
|
|
|
|
*Indicates that the setting is required in some, but not all situations.
|
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-response-body]]
|
|
|
|
|
==== {api-response-body-title}
|
|
|
|
|
|
|
|
|
|
A successful update user profile data API call returns a JSON structure
|
|
|
|
|
indicating that the request is acknowledged:
|
|
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
|
----
|
|
|
|
|
{
|
|
|
|
|
"acknowledged": true
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
// NOTCONSOLE
|
|
|
|
|
|
|
|
|
|
[[security-api-update-user-profile-data-example]]
|
|
|
|
|
==== {api-examples-title}
|
|
|
|
|
|
2022-03-15 05:25:10 +08:00
|
|
|
|
The following request updates a profile document for a `uid` matching
|
2022-06-04 21:23:20 +08:00
|
|
|
|
`u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0`:
|
2022-02-10 07:00:16 +08:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2022-06-04 21:23:20 +08:00
|
|
|
|
POST /_security/profile/u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0/_data
|
2022-02-10 07:00:16 +08:00
|
|
|
|
{
|
2022-04-14 06:47:34 +08:00
|
|
|
|
"labels": {
|
2022-06-04 21:23:20 +08:00
|
|
|
|
"direction": "east"
|
2022-02-10 07:00:16 +08:00
|
|
|
|
},
|
|
|
|
|
"data": {
|
|
|
|
|
"app1": {
|
|
|
|
|
"theme": "default"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
----
|
2022-06-04 21:23:20 +08:00
|
|
|
|
// TEST[setup:user_profiles]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
|
|
|
|
|
You can update the profile data to replace some keys and add new keys:
|
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2022-06-04 21:23:20 +08:00
|
|
|
|
POST /_security/profile/u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0/_data
|
2022-02-10 07:00:16 +08:00
|
|
|
|
{
|
2022-04-14 06:47:34 +08:00
|
|
|
|
"labels": {
|
2022-06-04 21:23:20 +08:00
|
|
|
|
"direction": "west"
|
2022-02-10 07:00:16 +08:00
|
|
|
|
},
|
|
|
|
|
"data": {
|
|
|
|
|
"app1": {
|
|
|
|
|
"font": "large"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
----
|
2022-06-04 21:23:20 +08:00
|
|
|
|
// TEST[continued]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
|
2022-06-04 21:23:20 +08:00
|
|
|
|
If you get the profile now, the consolidated profile data is returned:
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
|
|
|
|
GET /_security/profile/u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0?data=*
|
|
|
|
|
----
|
|
|
|
|
// TEST[continued]
|
2022-02-07 08:05:01 +08:00
|
|
|
|
|
2022-06-04 21:23:20 +08:00
|
|
|
|
[source,console-result]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
----
|
|
|
|
|
{
|
2022-08-10 09:21:38 +08:00
|
|
|
|
"profiles": [
|
|
|
|
|
{
|
|
|
|
|
"uid": "u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0",
|
|
|
|
|
"enabled": true,
|
|
|
|
|
"last_synchronized": 1642650651037,
|
|
|
|
|
"user": {
|
|
|
|
|
"username": "jackrea",
|
|
|
|
|
"roles": [
|
|
|
|
|
"admin"
|
|
|
|
|
],
|
|
|
|
|
"realm_name": "native",
|
|
|
|
|
"full_name": "Jack Reacher",
|
|
|
|
|
"email": "jackrea@example.com"
|
|
|
|
|
},
|
|
|
|
|
"labels": {
|
|
|
|
|
"direction": "west"
|
|
|
|
|
},
|
|
|
|
|
"data": {
|
|
|
|
|
"app1": {
|
|
|
|
|
"theme": "default",
|
|
|
|
|
"font": "large"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"_doc": {
|
|
|
|
|
"_primary_term": 88,
|
|
|
|
|
"_seq_no": 66
|
2022-02-10 07:00:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-10 09:21:38 +08:00
|
|
|
|
]
|
2022-02-10 07:00:16 +08:00
|
|
|
|
}
|
|
|
|
|
----
|
2022-08-10 09:21:38 +08:00
|
|
|
|
// TESTRESPONSE[s/1642650651037/$body.profiles.0.last_synchronized/]
|
|
|
|
|
// TESTRESPONSE[s/88/$body.profiles.0._doc._primary_term/]
|
|
|
|
|
// TESTRESPONSE[s/66/$body.profiles.0._doc._seq_no/]
|