DEPRECATED: This endpoint has been replaced by DELETE /admin/users .The new endpoint provides:
Cleaner RESTful structure
Better separation between users and invitations
Consistent response format
This endpoint will be removed in a future version.
This endpoint requires organization admin privileges. Only users with the org:admin role can bulk remove users from their organization.
Users cannot remove themselves from the organization using this endpoint. This prevents accidental lockouts.
Authentication
Bearer token for authentication. Must be from a user with org:admin role.
Body
Array of Clerk user IDs to remove from the organization (1-50 users per request)
Response
Whether all users were successfully removed
Total number of users requested to be removed
Number of users successfully removed
Number of users that failed to be removed
Array of successful removal results Clerk user ID that was successfully removed
Whether this specific removal was successful (always true in results array)
Array of failed removals (only present if there were failures) Clerk user ID that failed to be removed
Always false for error objects
Description of what went wrong
Examples
Basic Removal
Success Response
Partial Success Response
curl -X POST https://asteragents.com/api/admin/bulkRemove \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"userIds": [
"user_2ABC123DEF",
"user_2XYZ789GHI"
]
}'
Error Codes
Bad Request - Invalid request data, validation errors, or attempting to remove yourself
Unauthorized - Invalid or missing authentication
Forbidden - User is not an admin in the organization
Method Not Allowed - Only POST requests are accepted
Multi-Status - Some removals succeeded, others failed (partial success)
Workflow
Step 1: Get User IDs
First, use the Get Organization Users endpoint to retrieve user IDs:
// Get all users in organization
const usersResponse = await fetch ( '/api/admin/getUsersInOrg' , {
headers: { 'Authorization' : 'Bearer ' + token }
});
const users = await usersResponse . json ();
// Filter users you want to remove (e.g., by department)
// Note: publicMetadata is organization-scoped
const usersToRemove = users
. filter ( user => user . publicMetadata ?. department === 'marketing' )
. map ( user => user . id );
Step 2: Bulk Remove Users
Then use those IDs to remove users from the organization:
const removeResponse = await fetch ( '/api/admin/bulkRemove' , {
method: 'POST' ,
headers: {
'Authorization' : 'Bearer ' + token ,
'Content-Type' : 'application/json'
},
body: JSON . stringify ({
userIds: usersToRemove
})
});
Use Cases
Department Restructuring
Remove all users from a specific department:
# Get all users
users = requests.get( '/api/admin/getUsersInOrg' , headers = headers).json()
# Filter by department
marketing_users = [
user[ 'id' ] for user in users
if user.get( 'publicMetadata' , {}).get( 'department' ) == 'marketing'
]
# Remove them
response = requests.post( '/api/admin/bulkRemove' ,
headers = headers, json = { 'userIds' : marketing_users})
Inactive User Cleanup
Remove users who haven’t signed in recently:
const cutoffDate = new Date ( '2023-01-01' );
const inactiveUsers = users
. filter ( user => {
const lastSignIn = user . lastSignInAt ? new Date ( user . lastSignInAt ) : null ;
return ! lastSignIn || lastSignIn < cutoffDate ;
})
. map ( user => user . id );
// Remove inactive users
await fetch ( '/api/admin/bulkRemove' , {
method: 'POST' ,
headers: headers ,
body: JSON . stringify ({ userIds: inactiveUsers })
});
Role-Based Removal
Remove users with specific roles or metadata:
# Remove all temporary contractors
temp_contractors = [
user[ 'id' ] for user in users
if user.get( 'publicMetadata' , {}).get( 'role' ) == 'temp_contractor'
]
Features
Safe Operations : Built-in protection against self-removal and comprehensive error handling.
Self-Protection : Admins cannot accidentally remove themselves
Batch Processing : Handle up to 50 users per request efficiently
Detailed Results : Know exactly which users were removed and which failed
Partial Success : Continue processing even if some removals fail
Security Notes
Only organization admins can remove users
Removed users lose access to the organization immediately
Organization-scoped metadata is deleted when a user is removed from the organization
Users can be re-invited after removal (with fresh metadata)
Action is logged in Clerk audit logs
Webhooks will fire for organizationMembership.deleted events
Limits
Batch Size : 1-50 user IDs per request
User ID Validation : All user IDs must be valid Clerk user identifiers
Rate Limiting : Subject to Clerk’s API rate limits
Self-Removal : Cannot remove your own user ID (will fail with error)