See api-docs Menu

Create User

For details about each element in the User resource, see User Resource.

If you want to assign a role to a user, use the Assign Role to a User API.

If you want to update custom attribute values for a user, use the Set Custom Attribute Value API.

Resource URL

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

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 any one of the following scopes: Manage Users or Manage All.

Content-Type

required

string

Set to application/json.

Request Parameters

  • firstname, required, string

  • lastname, required, string

  • email, required, string

  • username, required, string

  • company, string

  • department, string

  • directory_id, string

  • distinguished_name, string

  • external_id, string

  • group_id, string

  • invalid_login_attempts, integer

  • locale_code, string

  • manager_ad_id, string

  • member_of, string

  • notes, string

  • openid_name, string

  • phone, string

  • samaccountname, string

  • title, string

  • userprincipalname, string

Sample Request Body

{
"firstname":"Lady",
"lastname":"GoGo",
"email":"lady@gogo.com",
"username":"lady@gogo"
}

Sample Response

{
    "status": {
        "error": false,
        "code": 200,
        "type": "success",
        "message": "Success"
    },
    "data": [
        {
            "activated_at": null,
            "created_at": "2015-11-13T21:08:25.923Z",
            "email": "lady@gogo.com",
            "username": "lady@gogo",
            "firstname": "Lady",
            "group_id": null,
            "id": 123456,
            "invalid_login_attempts": null,
            "invitation_sent_at": null,
            "last_login": null,
            "lastname": "GoGo",
            "locked_until": null,
            "notes": null,
            "openid_name": "lady",
            "locale_code": null,
            "password_changed_at": null,
            "phone": null,
            "status": null,
            "updated_at": "2015-11-13T21:08:26.227Z",
            "distinguished_name": null,
            "external_id": null,
            "directory_id": null,
            "member_of": null,
            "samaccountname": null,
            "userprincipalname": null,
            "manager_ad_id": null,
            "role_id": null
        }
 ]
}

Here are a few different errors that will return a 400 Bad Request status code.

{
    "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": "status is an excluded attribute for post request for user",
            "attribute": "status"
        }
    }
}

{
    "status": {
        "error": true,
        "code": 400,
        "type": "bad request",
        "message": {
            "description": "firstname is an required attribute for post request for user",
            "attribute": "firstname"
        }
 }
}

{
    "status": {
        "error": true,
        "code": 400,
        "type": "bad request",
        "message": {
            "description": "first_name is not a valid attribute for user model",
            "attribute": "first_name"
        }
 }
}

Typically, the following error means that your Authorization header value is missing or incorrectly formatted. The Authorization header value 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": "Invalid Request",
        "message": "Validation failed: Email must be unique, Username already taken"
    }
}

Typically, this error means that your access token value 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"
    }
}

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' \
-X POST \
-H "Authorization: bearer:<access_token>" \
-H "Content-Type: application/json" \
-d '{
  "firstname":"<firstname>",
  "lastname":"<lastname>",
  "email":"<email>",
  "username":"<username>"
}'

Python

See Work with OAuth 2.0 Tokens, Users, and Roles and Create a User.


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.