What options exist for bulk uploading users to <Pe...
# permit-saas
r
What options exist for bulk uploading users to Permit.io? Each user must be assigned at least one role. Can a default RBAC role be used when uploading users?
a
Hi @ROMAN VAZQUEZ MACIAS, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
Bulk Upload Options for Users You can bulk upload users to Permit.io using the bulk operations API (1) . Here are your options: Bulk Create Users You can create multiple users at once using a POST request to the
/bulk/users
endpoint :
Copy code
curl -X POST <https://api.permit.io/v2/facts/{proj_id}/{env_id}/bulk/users> \
 -H "Authorization: Bearer {your_permit_token}" \
 -H "Content-Type: application/json" \
 -d '{
 "operations": [{
 "key": "user|892179821739812389327",
 "email": "<mailto:jane@coolcompany.com|jane@coolcompany.com>",
 "first_name": "Jane",
 "last_name": "Doe",
 "attributes": {}
 }, ...]
 }'
(2) , (1) Bulk Role Assignment After creating users, you can assign roles in bulk using a separate API call :
Copy code
curl -X POST <https://api.permit.io/v2/facts/{proj_id}/{env_id}/role_assignments/bulk> \
 -H "Authorization: Bearer {your_permit_token}" \
 -H "Content-Type: application/json" \
 -d '[{
 "user": "892179821739812389327",
 "role": "admin",
 "tenant": "default"
 }, ...]'
Default Role Assignment Yes, you can use a default RBAC role when uploading users (3) . The documentation shows an example where users are automatically assigned a default "viewer" role during sync :
Copy code
// Assign the user a default role ("viewer") in the specified tenant
await permit.api.users.assignRole({
  user: user._id.toString() , // Reference the user by their unique ID
  role: "viewer", // Assign the "viewer" role
  tenant: tenantId, // Specify the tenant the user belongs to
}) ;
This approach allows you to set a baseline permission level for all new users , which you can later modify as needed through role assignment operations (1) . The bulk operations require two separate API calls - one to create users and another to assign roles . This gives you flexibility to create users first and then assign appropriate roles based on your RBAC policy configuration (4) .
To learn more, see the sources I considered: [[1] Perform Bulk Operations](https://docs.permit.io/how-to/bulk-operations) [[2] Node.js Bulk Requests Examples](https://docs.permit.io/sdk/nodejs/bulk-requests-examples) [[3] Implement Multi-Tenancy Role-Based Access Control (RBAC) in MongoDB](https://www.permit.io/blog/implement-multi-tenancy-rbac-in-mongodb) [[4] Configure your first RBAC Policy](https://docs.permit.io/overview/configure-your-first-rbac-policy)
Thanks for the feedback, glad I was helpful.