get-user-profile.asciidoc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. [role="xpack"]
  2. [[security-api-get-user-profile]]
  3. === Get user profiles API
  4. ++++
  5. <titleabbrev>Get user profiles</titleabbrev>
  6. ++++
  7. .New API reference
  8. [sidebar]
  9. --
  10. For the most up-to-date API details, refer to {api-es}/group/endpoint-security[Security APIs].
  11. --
  12. NOTE: The user profile feature is designed only for use by {kib} and
  13. Elastic’s {observability}, {ents}, and {elastic-sec} solutions. Individual
  14. users and external applications should not call this API directly. Elastic reserves
  15. the right to change or remove this feature in future releases without prior notice.
  16. Retrieves user profiles using a list of unique profile ID.
  17. [[security-api-get-user-profile-request]]
  18. ==== {api-request-title}
  19. `GET /_security/profile/<uid>`
  20. [[security-api-get-user-profile-prereqs]]
  21. ==== {api-prereq-title}
  22. To use this API, you must have _at least_ the `read_security`
  23. <<privileges-list-cluster,cluster privilege>> (or a greater privilege
  24. such as `manage_user_profile` or `manage_security`).
  25. [[security-api-get-user-profile-desc]]
  26. ==== {api-description-title}
  27. The get user profile API returns the user profile document matching a specified
  28. `uid`, which is generated when
  29. <<security-api-activate-user-profile,activating a user profile>>.
  30. [[security-api-get-user-profile-path-params]]
  31. ==== {api-path-parms-title}
  32. `uid`::
  33. (Required, string) The unique identifier for the user profile. You can specify multiple IDs as
  34. a comma-separated list.
  35. [[security-api-get-user-profile-query-params]]
  36. ==== {api-query-parms-title}
  37. `data`::
  38. (Optional, string) Comma-separated list of filters for the `data` field of
  39. the profile document. To return all content, use `data=*`. To return a
  40. subset of content, use `data=<key>` to retrieve the content nested under the
  41. specified `<key>`. Defaults to returning no content.
  42. [[security-api-get-user-profile-response-body]]
  43. ==== {api-response-body-title}
  44. A successful call returns the JSON representation of the user profile
  45. and its internal versioning numbers. The API returns an empty object
  46. if no profile document is found for the provided `uid`.
  47. The content of the `data` field is not returned by default to avoid deserializing
  48. a potential large payload.
  49. [[security-api-get-user-profile-example]]
  50. ==== {api-examples-title}
  51. [source,console]
  52. ----
  53. GET /_security/profile/u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0
  54. ----
  55. // TEST[setup:user_profiles]
  56. The API returns the following response for a `uid` matching `u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0`:
  57. [source,console-result]
  58. ----
  59. {
  60. "profiles": [
  61. {
  62. "uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0",
  63. "enabled": true,
  64. "last_synchronized": 1642650651037,
  65. "user": {
  66. "username": "jacknich",
  67. "roles": [
  68. "admin", "other_role1"
  69. ],
  70. "realm_name": "native",
  71. "full_name": "Jack Nicholson",
  72. "email": "jacknich@example.com"
  73. },
  74. "labels": {
  75. "direction": "north"
  76. },
  77. "data": {}, <1>
  78. "_doc": {
  79. "_primary_term": 88,
  80. "_seq_no": 66
  81. }
  82. }
  83. ]
  84. }
  85. ----
  86. // TESTRESPONSE[s/1642650651037/$body.profiles.0.last_synchronized/]
  87. // TESTRESPONSE[s/88/$body.profiles.0._doc._primary_term/]
  88. // TESTRESPONSE[s/66/$body.profiles.0._doc._seq_no/]
  89. <1> No content is returned in the `data` field by default.
  90. The following request retrieves a subset of `data` that's nested under the
  91. key `app1`, along with the user's profile:
  92. [source,console]
  93. ----
  94. GET /_security/profile/u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0?data=app1.key1
  95. ----
  96. // TEST[continued]
  97. [source,console-result]
  98. ----
  99. {
  100. "profiles": [
  101. {
  102. "uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0",
  103. "enabled": true,
  104. "last_synchronized": 1642650651037,
  105. "user": {
  106. "username": "jacknich",
  107. "roles": [
  108. "admin", "other_role1"
  109. ],
  110. "realm_name": "native",
  111. "full_name": "Jack Nicholson",
  112. "email": "jacknich@example.com"
  113. },
  114. "labels": {
  115. "direction": "north"
  116. },
  117. "data": {
  118. "app1": {
  119. "key1": "value1"
  120. }
  121. },
  122. "_doc": {
  123. "_primary_term": 88,
  124. "_seq_no": 66
  125. }
  126. }
  127. ]
  128. }
  129. ----
  130. // TESTRESPONSE[s/1642650651037/$body.profiles.0.last_synchronized/]
  131. // TESTRESPONSE[s/88/$body.profiles.0._doc._primary_term/]
  132. // TESTRESPONSE[s/66/$body.profiles.0._doc._seq_no/]
  133. If there has been any errors when retrieving the user profiles, they are returned in the `errors` field:
  134. [source,js]
  135. --------------------------------------------------
  136. {
  137. "profiles": [],
  138. "errors": {
  139. "count": 1,
  140. "details": {
  141. "u_FmxQt3gr1BBH5wpnz9HkouPj3Q710XkOgg1PWkwLPBW_5": {
  142. "type": "resource_not_found_exception",
  143. "reason": "profile document not found"
  144. }
  145. }
  146. }
  147. }
  148. --------------------------------------------------
  149. // NOTCONSOLE