See api-docs Menu

Lock User Account

Use this call to lock a user’s account based on the policy assigned to the user, for a specific time you define in the request, or until you unlock it.

For details, see Request Parameter.

Resource URL

https://api.<us_or_eu>.onelogin.com/api/1/users/:id/
lock_user

Header Parameters

Authorization

required

string

Set to bearer:<access_token>.

Set <access_token> to the access token you generated using the Generate Token API.

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 the Manage All scope only.

Content-Type

required

string

Set to application/json.

Resource Parameter

id

required

string

Set to the id of the user whose account you want to lock. If you don’t know the user’s id, use the Get Users API call to return all users and their id values.

Request Parameter

locked_until

required

integer

Set to the number of minutes for which you want to lock the user account.

Set to 0 if you want to lock the user account based on the Lock effective period set in the policy assigned to the user.

If no policy is assigned to the user, setting this value to 0 will lock the user’s account until you unlock it

Request Body

{
   "locked_until":1
}

Sample Response

{
    "status": {
        "type": "success",
        "code": 200,
        "message": "Success",
        "error": false
    }
}
{
    "status": {
        "error": true,
        "code": 400,
        "type": "bad request",
        "message": "Input JSON is not valid"
    }
}

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"
    }
}

{
    "status": {
        "error": true,
        "code": 400,
        "type": "bad request",
        "message": "locked_until should be -> integer"
    }
}

Typically, the following error means that the user ID is not an integer. The user ID must be an integer.

{
    "status": {
        "error": true,
        "code": 400,
        "type": "bad request",
        "message": {
            "attribute": "id",
            "description": "ID is incorrect"
        }
    }
}

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 All scope only.

{
    "status": {
        "error": true,
        "code": 401,
        "type": "Unauthorized",
        "message": "Insufficient Permission"
    }
}

Typically, the following error means that the access token is invalid.

{
    "status": {
        "error": true,
        "code": 401,
        "type": "Unauthorized",
        "message": "Authentication Failure"
    }
}
{
    "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 99999999 was not found"
    }
}

Postman Collection

Replace sample variables indicated by < > in the sample request body with your actual values. Also, be sure to set Postman-specific environment variables indicated by {{ }}.

Download for the Users API

Sample Code

cURL

Replace sample values indicated by < > with your actual values.

curl "https://api.<us_or_eu>.onelogin.com/api/1/users/<user_id>/lock_user" \
-X PUT \
-H "Authorization: bearer:<access_token>" \
-H "Content-Type: application/json" \
-d '{ 
    "locked_until": <integer_in_minutes>
}'

Python

See Work with OAuth 2.0 Tokens, Users, and Roles.


Have a Question?

Have a how-to question? Seeing a weird error? Ask us about it on StackOverflow.

Found a bug? Submit a support ticket.

Have a product idea or request? Share it with us in our Ideas Portal.