Update User by ID
Use to update a user by ID using these request parameters.
Here are some API calls you can use to make other common updates to users:
To update roles for a user, use the Assign Role to a User or Remove Role from a User API.
To update custom attribute values for a user, use the Set Custom Attribute Value API.
To remove a group from a user, use
"group_id": null
.- To set the State for a user, you can use either this API (using the
state
request parameter) or the Set User State API, with one exception: if a user is in the Unlicensed state (id=3) and you want to change their state, you must use the Set User State API.
For details about each element in the User resource, see User Resource.
Resource URL
Before calling this API, consider using its version /2 equivalent.
https://<subdomain>/api/1/users/:id
Header Parameters
Authorization required string |
Set to Set The access token must have been generated using an API credential pair created using the scope required to call this API. This API can be called using any one of the following scopes: |
Content-Type required string |
Set to application/json . |
Resource Parameter
id required integer |
Set to the |
Request Parameters
-
company, string
-
department, string
-
directory_id, string
-
distinguished_name, string
-
email, string
-
external_id, string
-
firstname, string
-
group_id, integer
-
invalid_login_attempts, string
-
lastname, string
-
locale_code, string
-
manager_ad_id, string
-
manager_user_id, integer
Note: external_id for manager mapping works for Directory syncs. For APIs, set it via manager_user_id.
-
member_of, string
-
notes, string
-
openid_name, string
-
phone, string
-
samaccountname, string
state, integer
Valid values include:
Unapproved: 0
Approved (licensed): 1
Rejected: 2
Unlicensed: 3Note. To set the State for a user, you can use either this API or the Set User State API, with one exception: if a user is in the Unlicensed state (id=3) and you want to change their state, you must use the Set User State API.
-
status, integer
Valid values include:
Unactivated: 0
Active: 1
Suspended: 2
Locked: 3
Password expired: 4
Awaiting password reset: 5
Pending password: 7
Security questions required: 8 -
title, string
-
username, string
-
userprincipalname, string
-
custom_attributes, object
Sample Request Body
{
"lastname":"Gonzales-Jones",
"state":3,
"custom_attributes": {
"best_trick": "front flip"
}
}
Sample Response
- 200 OK
- 400 Bad Req.
- 401 Unauth.
- 403 Forbid.
- 404 Not Found
{
"status": {
"error": false,
"code": 200,
"type": "success",
"message": "Success"
},
"data": [
{
"activated_at": null,
"created_at": "2015-11-25T03:32:44.478Z",
"email": "justine.gonzales@test.com",
"username": "justine@gonzales",
"firstname": "Justine",
"group_id": null,
"id": 11111111,
"invalid_login_attempts": null,
"invitation_sent_at": null,
"last_login": null,
"lastname": "Gonzales-Jones",
"locked_until": null,
"notes": null,
"openid_name": "justine",
"locale_code": null,
"password_changed_at": null,
"phone": null,
"status": null,
"updated_at": "2015-12-01T18:45:53.086Z",
"distinguished_name": null,
"external_id": null,
"directory_id": null,
"member_of": null,
"samaccountname": null,
"userprincipalname": null,
"manager_ad_id": null,
"role_id": null,
"state": 3,
"custom_attributes": {
"best_trick": "front flip"
}
}
]
}
Note that custom_attributes will only be included in the response body if they were sent in the request body.
Here are a few different errors that will return a 400 Bad Request
status code.
{
"status": {
"error": true,
"code": 400,
"type": "bad request",
"message": {
"description": "last is not a valid attribute for user model",
"attribute": "last"
}
}
}
{
"status": {
"error": true,
"code": 400,
"type": "bad request",
"message": "Content Type is not specified or specified incorrectly.
Content-Type header must be set to application/json"
}
}
{
"status": {
"error": true,
"code": 400,
"type": "bad request",
"message": {
"description": "id is an excluded attribute for put request for user",
"attribute": "id"
}
}
}
{
"status": {
"error": true,
"code": 400,
"type": "bad request",
"message": {
"description": "status has incorrect data type. It should be -> integer",
"attribute": "status"
}
}
}
The following error means you are trying to change the state
of a user that is currently in the Unlicensed state (value=3). You must use the Set User State API if you want to change a user out of the Unlicensed state.
{
"status": {
"error": true,
"code": 400,
"type": "bad request",
"message": "user is unlicensed"
}
}
Typically, the following error means that the Authorization
header is missing or incorrectly formatted. The Authorization
header should use this format: bearer:<access_token>
.
{
"status": {
"error": true,
"code": 400,
"type": "bad request",
"message": "Authorization Information is incorrect"
}
}
Typically, this error means that the access token is invalid.
{
"status": {
"error": true,
"code": 401,
"type": "Unauthorized",
"message": "Authentication Failure"
}
}
Typically, the following error means that the access token used to make the call was generated using API credentials that have insufficient permissions. This API can be called using the Manage Users
or Manage All
scope.
{
"status": {
"error": true,
"code": 401,
"type": "Unauthorized",
"message": "Insufficient Permission"
}
}
{
"status": {
"error": true,
"code": 403,
"type": "forbidden",
"message": "user is not authorized to access this User"
}
}
{
"status": {
"error": true,
"code": 404,
"type": "not found",
"message": "User for id 11111111 was not found"
}
}
Postman Collection
- Clicking Run in Postman button navigates to the page where you can fork the collection to your workspace. Forking the collection into your workspace will enable you to contribute to the source collection using pull requests. You can also view the collection in a public workspace if you like and even import a copy of the collection using the links present on the screen.
Sample Code
cURL
Replace sample values indicated by < >
with your actual values.
curl 'https://<subdomain>/api/1/users/<id>' \
-X PUT \
-H "Authorization: bearer:<access_token>" \
-H "Content-Type: application/json" \
-d '{
"lastname":"<lastname>"
}'
Python
See Work with OAuth 2.0 Tokens, Users, and Roles.
Have a Question?
Found a problem or a bug? Submit a support ticket.
Looking for walkthroughs or how-to guides on OneLogin's user and admin features? Check out the documentation in our Knowledge Base.
Have a product idea or request? Share it with us in our Ideas Portal.