Hi there, I want to get the login history for a us...
# ask-a-descoper
e
Hi there, I want to get the login history for a user via management API. The doc appears to be incomplete, as it doesn’t indicate any body in the POST request (it’s a little odd that it’s a POST instead of a GET). So I want to be sure I’m doing the right thing. Everything I try results in a
400
error with:
Copy code
{
  "errorCode": "E011001",
  "errorDescription": "Request is malformed"
}
https://docs.descope.com/api/management/users/users-auth-history
✅ 1
d
Perfect! I found the exact documentation for the login history API. Based on the search results, I can see that the API expects an empty JSON object
{}
in the request body. Request Body Issue The login history API requires an empty JSON object in the request body . You're getting a 400 error because the API expects a JSON body, even though it's empty.
Copy code
curl -X POST "<https://api.descope.com/v1/mgmt/user/history>"  
  -H "Authorization: Bearer <token>"  
  -H "Content-Type: application/json"  
  -d '{}'
Why POST Instead of GET The endpoint uses POST because it follows REST conventions for management APIs that may need to support filtering parameters in the future. The empty body structure allows for potential expansion without breaking changes. Common Issues 1. Missing
Content-Type: application/json
header 2. Sending no body instead of empty JSON object
{}
3. Invalid authorization token format The API returns login history for all users in your project . Each entry includes userId, loginTime, city, country, IP, and selectedTenant. Get User's Login History | API Reference | Descope Documentation
e
Wait a second, if I make this request I will get the login history for all the users in the app? We have 40k users… I just want the login history for a single user, how do I specify that?
d
Based on my search through the documentation, I can see that the login history API documentation shows an empty request body
{}
in the example. However, looking at other management APIs like "Log user out of all sessions" which accepts both
loginId
and
userId
parameters , it appears the login history API may support filtering but the documentation is incomplete. Missing Documentation The documentation for the login history API appears incomplete - it only shows an empty request body
{}
which would indeed return all users' login history . However, based on other similar management APIs, it likely supports filtering parameters. Try These Parameters Based on patterns from other Descope management APIs, try adding user identification to the request body:
Copy code
curl -X POST "<https://api.descope.com/v1/mgmt/user/history>"  
  -H "Authorization: Bearer <token>"  
  -H "Content-Type: application/json"  
  -d '{
    "loginId": "<mailto:user@example.com|user@example.com>"
  }'
Or with userId:
Copy code
curl -X POST "<https://api.descope.com/v1/mgmt/user/history>"  
  -H "Authorization: Bearer <token>"  
  -H "Content-Type: application/json"  
  -d '{
    "userId": "U2FsdGVkX1..."
  }'
Alternative Approach If filtering isn't supported, you could use the Search Users API to get login history data, which does support filtering by specific users . The documentation appears incomplete for this specific endpoint. I'd recommend testing the parameters above, and if they don't work, you may need to contact Descope support for the correct filtering syntax. Log user out of all sessions | API Reference | Descope Documentation Get User's Login History | API Reference | Descope Documentation Search Users | API Reference | Descope Documentation
e
I’ve tried body data like that and also a
userIds
array, but I just get the response that it’s malformed.
d
The documentation for the login history API is incomplete and doesn't specify the correct request body parameters for filtering by specific users. Since you're getting malformed request errors with the standard patterns, this needs clarification from the Descope team. I'm connecting you with a member of the Descope support team now or you can also reach support directly at support.descope.com. They'll be able to provide the correct request body structure for filtering login history by specific users, which isn't properly documented in the current API reference.
e
Ok, also I tried the
search
API but it doesn’t give login history. I really just need the last login timestamp for this user…
d
Perfect! I found the solution. There's a specific field available for last login time. Use Custom Claims for Last Login Time The easiest way to get the last login timestamp is through custom claims in JWT templates. Descope provides a built-in field
user.lastAuth.time
that contains the last time the user logged in . Setup Custom Claims 1. Go to your Descope console → Project Settings → JWT Templates 2. Add
user.lastAuth.time
to your session token custom claims 3. The timestamp will be included in every user's JWT Alternative: Session History API There's also a Session History API that requires the user's refresh token :
Copy code
curl -X GET "<https://api.descope.com/v1/auth/history>"  
  -H "Authorization: Bearer <ProjectID:RefreshJWT>"
This returns the user's session history including geo-location and timestamps, but requires the user to be authenticated. Recommendation For your use case, custom claims with
user.lastAuth.time
is the most efficient approach - you'll get the last login timestamp directly in the JWT without additional API calls. Dynamic Keys &amp; Values | Descope Documentation My Details | API Reference | Descope Documentation
e
ok, but I need this info now for a user who may not have logged in for a few days, this isn’t something where I can make a change in the application.
d
You're right - you need the historical data now, not future logins. Unfortunately, based on the documentation search, there doesn't appear to be a working way to get individual user login history via the management API currently. Current Limitations The login history management API documentation is incomplete and doesn't specify how to filter by specific users. You've already tried the standard patterns (
loginId
,
userId
,
userIds
array) and they're returning malformed request errors. Possible Workarounds 1. Check if Load User API includes last login - The Load User API might include last login data in the user object, though it's not explicitly documented 2. Audit logs - If you have audit logging enabled, login events might be available there 3. Custom tracking - If you've been storing login events in your own database Immediate Solution Since the API documentation is incomplete and the standard filtering approaches aren't working, the Descope support team you're already connected with will need to provide: 1. The correct request body format for filtering login history by user 2. Or confirm if this filtering capability exists at all 3. Alternative approaches for getting historical login data This appears to be a gap in the current API documentation/functionality that requires direct support assistance to resolve.
a
Hey Ed, please DM me your project id
meanwhile, try this
endpoint: <https://api.descope.com/v1/mgmt/audit/search>
payload: {
loginIds: [loginId],
actions: ["LoginSucceed", "LoginSucceeded"],
from: 0,
to: Date.now(),
limit: 10,
}
`Authorization: `Bearer ${process.env.DESCOPE_PROJECT_ID}:${process.env.DESCOPE_MANAGEMENT_KEY}``
e
Hi Aditya, cool, I was able to get that to work in my test environment.
loginIds
did not work, nothing was filtered. But if I use
userIds
instead, then I get the results filtered down to the user I’m looking for. Thanks!
🙌 1