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

Before calling this API, consider using its version /2 equivalent.

https://<subdomain>/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, a unique email or username is required, string

  • username, a unique email or username is required, string

  • company, string

  • department, string

  • directory_id, integer

  • distinguished_name, string

  • external_id, string

  • group_id, integer

  • invalid_login_attempts, integer

  • locale_code, string

  • member_of, string

  • openid_name, string

  • phone, string

  • samaccountname, string

  • title, string

  • custom_attributes, object

Sample Request Body

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

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,
            "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": "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

Run In Postman

    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' \
-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?

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.