Last Updated: Sep 4, 2024
Overview
When using the “Import users to Auth0” feature with custom databases, it is impossible to add the user as a member to a predefined organization. The “Import users to Auth0” feature for custom databases does not currently support automatically adding imported users to predefined organizations.
Applies To
- Import Users
Cause
This feature is in our backlog, but there’s no timeline for when it will be available. In the meantime, please use the workaround detailed in the Solution section.
Solution
Step 1: Create Organizations
Choose one of these methods to create organizations:
- Use the “create organization” API endpoint.
- Manually add organizations through the Auth0 dashboard.
Step 2: Add Users to Organizations
Once users are migrated:
- Use the post_members endpoint to add users to organizations.
- When adding users, provide the user_ids in the format
connection_type|user_id
(e.g.,auth0|a1b2c3d4e5f6a7b8c9d0e1f2a3
).
Here’s an example request:
curl -X POST 'https://<tenant domain>/api/v2/organizations/<organization id>/members' \
-H 'Authorization: Bearer <access token>' \
-H 'Content-Type: application/json' \
-d '{
"members": [
"auth0|a1b2c3d4e5f6a7b8c9d0e1f2a3",
"auth0|b4c5d6e7f8a9b0c1d2e3f4a5b6",
"auth0|c7d8e9f0a1b2c3d4e5f6a7b8c9",
"auth0|d0e1f2a3b4c5d6e7f8a9b0c1d2",
"auth0|e3f4a5b6c7d8e9f0a1b2c3d4e5"
]
}'
While this requires more steps, achieve the outcome of having all imported users belong to the desired organization.
Another alternative would be to use a post-login action that would add the member to the organization once they log in for the first time, so they are immediately added. However, this would create more overhead as a separate API request would be made for each user.