update-user-profile-data.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. [role="xpack"]
  2. [[security-api-update-user-profile-data]]
  3. === Update user profile data API
  4. ++++
  5. <titleabbrev>Update user profile data</titleabbrev>
  6. ++++
  7. NOTE: The user profile feature is designed only for use by {kib} and
  8. Elastic’s {observability}, {ents}, and {elastic-sec} solutions. Individual
  9. users and external applications should not call this API directly. Elastic reserves
  10. the right to change or remove this feature in future releases without prior notice.
  11. Updates specific data for the user profile that's associated with the specified
  12. unique ID.
  13. [[security-api-update-user-profile-data-request]]
  14. ==== {api-request-title}
  15. `POST /_security/profile/<uid>/_data`
  16. [[security-api-update-user-profile-data-prereqs]]
  17. ==== {api-prereq-title}
  18. To use this API, you must have one of the following privileges:
  19. * The `manage_user_profile` cluster privilege.
  20. * The `update_profile_data` global privilege for the namespaces that are
  21. referenced in the request.
  22. [[security-api-update-user-profile-data-desc]]
  23. ==== {api-description-title}
  24. The update user profile API updates the `labels` and `data` fields of an
  25. existing user profile document with JSON objects. New keys and their values are
  26. added to the profile document, and conflicting keys are replaced by data that's
  27. included in the request.
  28. For both `labels` and `data`, content is namespaced by the top-level fields.
  29. The `update_profile_data` global privilege grants privileges for updating only
  30. the allowed namespaces.
  31. [[security-api-update-user-profile-data-path-params]]
  32. ==== {api-path-parms-title}
  33. `uid`::
  34. (Required, string) A unique identifier for the user profile.
  35. [[security-api-update-user-profile-data-query-params]]
  36. ==== {api-query-parms-title}
  37. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=if_seq_no]
  38. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=if_primary_term]
  39. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=refresh]
  40. `uid`::
  41. (Required, string) A unique identifier for the user profile.
  42. [[security-api-update-user-profile-data-request-body]]
  43. ==== {api-request-body-title}
  44. `labels`::
  45. (Required*, object)
  46. Searchable data that you want to associate with the user profile.
  47. This field supports a nested data structure. Within the `labels` object,
  48. top-level keys cannot begin with an underscore (`_`) or contain a period (`.`).
  49. `data`::
  50. (Required*, object)
  51. Non-searchable data that you want to associate with the user profile.
  52. This field supports a nested data structure. Within the `data` object, top-level
  53. keys cannot begin with an underscore (`_`) or contain a period (`.`)
  54. The `data` object is not searchable, but can be retrieved with the
  55. <<security-api-get-user-profile,Get user profile API>>.
  56. *Indicates that the setting is required in some, but not all situations.
  57. [[security-api-update-user-profile-data-response-body]]
  58. ==== {api-response-body-title}
  59. A successful update user profile data API call returns a JSON structure
  60. indicating that the request is acknowledged:
  61. [source,js]
  62. ----
  63. {
  64. "acknowledged": true
  65. }
  66. ----
  67. // NOTCONSOLE
  68. [[security-api-update-user-profile-data-example]]
  69. ==== {api-examples-title}
  70. The following request updates a profile document for a `uid` matching
  71. `u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0`:
  72. [source,console]
  73. ----
  74. POST /_security/profile/u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0/_data
  75. {
  76. "labels": {
  77. "direction": "east"
  78. },
  79. "data": {
  80. "app1": {
  81. "theme": "default"
  82. }
  83. }
  84. }
  85. ----
  86. // TEST[setup:user_profiles]
  87. You can update the profile data to replace some keys and add new keys:
  88. [source,console]
  89. ----
  90. POST /_security/profile/u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0/_data
  91. {
  92. "labels": {
  93. "direction": "west"
  94. },
  95. "data": {
  96. "app1": {
  97. "font": "large"
  98. }
  99. }
  100. }
  101. ----
  102. // TEST[continued]
  103. If you get the profile now, the consolidated profile data is returned:
  104. [source,console]
  105. ----
  106. GET /_security/profile/u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0?data=*
  107. ----
  108. // TEST[continued]
  109. [source,console-result]
  110. ----
  111. {
  112. "profiles": [
  113. {
  114. "uid": "u_P_0BMHgaOK3p7k-PFWUCbw9dQ-UFjt01oWJ_Dp2PmPc_0",
  115. "enabled": true,
  116. "last_synchronized": 1642650651037,
  117. "user": {
  118. "username": "jackrea",
  119. "roles": [
  120. "admin"
  121. ],
  122. "realm_name": "native",
  123. "full_name": "Jack Reacher",
  124. "email": "jackrea@example.com"
  125. },
  126. "labels": {
  127. "direction": "west"
  128. },
  129. "data": {
  130. "app1": {
  131. "theme": "default",
  132. "font": "large"
  133. }
  134. },
  135. "_doc": {
  136. "_primary_term": 88,
  137. "_seq_no": 66
  138. }
  139. }
  140. ]
  141. }
  142. ----
  143. // TESTRESPONSE[s/1642650651037/$body.profiles.0.last_synchronized/]
  144. // TESTRESPONSE[s/88/$body.profiles.0._doc._primary_term/]
  145. // TESTRESPONSE[s/66/$body.profiles.0._doc._seq_no/]