REST API to get the logged in user details

sahilkhanna
Tera Expert

I'm new to Service Now and am exploring REST APIs.

 

I have created a user named "Ajay". I have got the access_token of this user. I am getting the details of this user using the below request.

curl --location 'https://dev191.service-now.com/api/now/table/sys_user' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer Vmxn6CYIC...............OohTqA'

The request returns the list of all users. However, I want the request to return only the user identified in the access_token.

2 ACCEPTED SOLUTIONS

JenniferRah
Mega Sage

Maybe what you are looking for is this?

GET instance.service-now.com/api/now/ui/user/current_user

View solution in original post

Juhi Poddar
Kilo Patron

Hello @sahilkhanna 

Set the endpoint to "https://dev191.service-now.com/api/now/ui/user/current_user"

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

7 REPLIES 7

JenniferRah
Mega Sage

Maybe what you are looking for is this?

GET instance.service-now.com/api/now/ui/user/current_user

dgarad
Giga Sage

Hi @sahilkhanna 

pass the sys_id of user to URL

https://dev191.service-now.com/api/now/table/sys_user/sys_id

 

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Ankur Bawiskar
Tera Patron
Tera Patron

@sahilkhanna 

your endpoint is to get all user records so it won't return specific user but will return all users

you need to pass the user sysId to get the particular user from sys_user table

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

vishwajeet5550
Mega Guru

 

{
  "result": [
    {
      "sys_id": "1234567890abcdef",
      "user_name": "Ajay",
      "first_name": "Ajay",
      "last_name": "Sharma",
      "email": "ajay@example.com",
      ...
    }
  ]
}

 

 

For a quick way to fetch the authenticated user's details, use the /api/now/table/sys_user/me endpoint. This is the simplest and most effective approach, as it ensures that you're getting the details of the user tied to the provided access_token.

If you want to filter by user_name or sys_id explicitly, you can use query parameters in the /api/now/table/sys_user endpoint.