User Import API
API Reference for the User Import API that developers can use to bulk import users from another system to their Authgear project.
The User Import API is an API that supports the bulk import of users from another system to an Authgear project. This API is not part of the Admin API GraphQL. However, the API endpoints require the Admin API JWT token to access it.
The following are other important things to note about the User Import API:
The actual process of importing the users is asynchronous. This means execution is done in the background. The API provides an endpoint developers can use to query the status of the import.
Once an import is initiated successfully, the API will return an ID for the task. This ID is required to query the status of the import.
The body of HTTP requests to the API has a limit of 500KB.
Using the User Import API does not trigger the
user.pre_create
anduser.created
hooks.The API supports the Bcrypt password format. To import passwords using this format specify the format
type
andpassword_hash
in an object that will be the value of the user'spassword
field. For example:
Endpoints
The Import User API has two endpoints, one for initiating a user import task and the other for checking the status of the task. The endpoints only support secure HTTPS request and require a valid Admin API JWT token using Bearer
authorization header (Authorization: Bearer <Admin API JWT Token>
).
Here are more details about the endpoints and their expected inputs.
Initiate Import
POST
/_api/admin/users/import
Use this endpoint to create a new user import task.
Headers
Name | Value |
---|---|
Content-Type |
|
Authorization |
|
Host |
|
Body
The Initiate Import endpoint accepts JSON input via an HTTP(S) request body. The following is an example of the input:
Input Format
The endpoint that initiates an import accepts JSON input via an HTTP request body. The following sample JSON document shows the expected structure and fields of the input:
To understand the input better, let's take a close look at the three fields (upsert
, identifier
, records
) that are directly on the root of the above JSON document.
upsert
: This is an optional boolean that isfalse
by default. When the value for this field is set totrue
and a user already exists with the same identity, the user's data is updated based on the update behavior for each attribute.identifier
: This field is required. It tells Authgear what attribute to use to identify an existing user. The following strings are the accepted values:preferred_username
,email
, andphone_number
.records
: This is where a developer can provide the data of all the users they wish to import in an array. Each direct object in the array represents a single user. Within the object, you can define the standard attributes for the user using the various fields as shown in the sample above. You may also define custom attributes in an object nested inside thecustom_attributes
field as also shown above.
Response
id
: this is the unique ID for the import task that was created. The ID is required to check the status of the task.
status
: the value for status is pending
after the import task is created and completed
once the user import task is finished.
Check Status
GET
/_api/admin/users/import/{ID}
Use this endpoint to query the status of an existing user import task. Replace {ID}
with a valid ID for a user import task.
Headers
Name | Value |
---|---|
Authorization |
|
Host |
|
Response
Update Behavior
The update behavior for an attribute determines how Authgear will treat that attribute when an existing user has the same value for the specified identifier
type. For example, if the identifier
is "email", the update behavior for each attribute is how Authgear will treat the attribute if a user already exists with the same email address as the current user you're trying to import.
Each attribute can have one of the three different types of update behavior described below:
UPDATED_IF_PRESENT_AND_REMOVED_IF_NULL: An attribute with this update behavior will update the user's attribute to the new value if that new value is not null. If the new value is explicitly null, the attribute will be deleted for the user. And if the attribute is absent, no operation is done.
UPDATED_IF_PRESENT: When this is the update behavior of an attribute, it will be updated if it is present. If the attribute is not present, no operation is done.
IGNORED: If a user exists already, the new value of this attribute is ignored. If the attribute is absent, nothing is done.
Update Behavior of each field
The following table shows all attributes and their update behavior for reference purposes:
Item | Update Behavior | Description |
---|---|---|
| UPDATED_IF_PRESENT_AND_REMOVED_IF_NULL | If it is not |
| UPDATED_IF_PRESENT | For example, in the first import, if |
All other standard attributes | UPDATED_IF_PRESENT_AND_REMOVED_IF_NULL | In particular, |
| UPDATED_IF_PRESENT_AND_REMOVED_IF_NULL | For each attribute in |
| UPDATED_IF_PRESENT | If present, the roles and groups of the user will match the value. For example, supposed the user originally has |
| UPDATED_IF_PRESENT | Re-importing a record without specifying |
| IGNORED | If it was not provided when the record was first imported, subsequent import CANNOT add it back. |
| UPDATED_IF_PRESENT_AND_REMOVED_IF_NULL | If provided, the user can perform 2FA with email OTP. |
| UPDATED_IF_PRESENT_AND_REMOVED_IF_NULL | If provided, the user can perform 2FA with phone OTP. |
| IGNORED | If it was not provided when the record was first imported, subsequent import CANNOT add it back. |
| IGNORED | If it was not provided when the record was first imported, subsequent import CANNOT add it back. |
Usage Example
The following is a detailed guide with examples of using the User Import API to bulk import users and check the status of tasks.
Import Users using User Import APILast updated