SCIM provisioning
Provision users and groups from Okta, Entra ID or Google Workspace into ulex over SCIM 2.0: register a directory, paste the base URL and token, handle create/update/deactivate, use Bulk for large directories, and verify the whole loop.
SCIM 2.0 is how an enterprise customer's HR system tells your app who works there. It is the difference between "here is a directory" and "here is a directory that keeps itself current".
ulex is a SCIM server at /scim/v2. Okta, Entra ID, Google Workspace, OneLogin and JumpCloud push into it with no adapter in between.
#1. Register the directory
curl -sS -X POST "$BASE/directories" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: 3c9d1f77-0b2e-4a58-9d61-5e7a2c40b913" \
-d '{
"name": "Acme (Okta)",
"provider": "okta",
"domain": "acme.example",
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"inbound_scim_enabled": true,
"scim_poll_interval_seconds": 900
}'{
"id": "dir_01M3PSVBF8038RK2MW2N263Q2B",
"object": "directory",
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"name": "Acme (Okta)",
"provider": "okta",
"state": "active",
"domain": "acme.example",
"scim_base_url": "https://ulexid.com/api/v1/scim/v2",
"inbound_scim_enabled": true,
"scim_poll_interval_seconds": 900,
"has_scim_token": false,
"has_inbound_scim_token": true,
"has_client_secret": false,
"last_synced_at": null,
"last_sync_status": "never",
"last_sync_error": null
}provider ∈ okta | entra_id | azure_ad | google_workspace | onelogin | jumpcloud | scim_generic | ulex_mock. The provider affects polling behaviour and the attribute mapping defaults; the wire protocol is identical.
#2. Get the SCIM configuration
curl -sS "$BASE/directories/dir_01M3PSVBF8038RK2MW2N263Q2B/scim" -H "Authorization: Bearer $ULEX_API_KEY"{
"base_url": "https://ulexid.com/api/v1/scim/v2",
"bearer_token": "scim_7Bq4Nxf2Vk9Lc3MdT6hR8wS1yP5aG0eJ",
"inbound_scim_enabled": true,
"poll_interval_seconds": 900,
"user_filter": null,
"group_filter": null,
"deprovision_upstream_removals": true,
"schemas_supported": [
"urn:ietf:params:scim:schemas:core:2.0:User",
"urn:ietf:params:scim:schemas:core:2.0:Group"
],
"bulk_supported": true,
"max_operations_per_bulk": 100
}bearer_token is shown once per rotation. Requires the scim:provision scope. If you lose it, PATCH /directories/{id} with a new scim_token — do not delete and recreate the directory, which loses the scim_id mappings.
#3. Paste it into the customer's IdP
| Okta | Value |
|---|---|
| SCIM base URL | https://ulexid.com/api/v1/scim/v2 |
| OAuth Bearer Token | scim_… |
| User create | POST /Users |
| User update | PATCH /Users/{id} |
| User deactivate | DELETE /Users/{id} |
| Group push | POST /Groups, PATCH /Groups/{id} |
| Entra ID | Value |
|---|---|
| Tenant URL | https://ulexid.com/api/v1/scim/v2 |
| Secret token | scim_… |
| Provisioning mode | Standard |
Test the connection before you enable provisioning. Okta sends GET /Users?filter=userName eq "probe@<customer-domain>". A 200 with an empty Resources array is the success case; a 401 means the token is wrong or the directory is not active.
#4. What each call does
#Create
curl -sS -X POST "$BASE/scim/v2/Users" \
-H "Authorization: Bearer scim_7Bq4Nxf2Vk9Lc3MdT6hR8wS1yP5aG0eJ" \
-H "Content-Type: application/scim+json" \
-d '{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"userName": "pat@acme.example",
"name": { "givenName": "Pat", "familyName": "Iyer", "formatted": "Pat Iyer" },
"displayName": "Pat Iyer",
"emails": [{ "value": "pat@acme.example", "type": "work", "primary": true }],
"active": true,
"title": "Support Engineer",
"department": "Customer Success",
"preferredLanguage": "en-US",
"externalId": "okta-00u9xK2mB7yLt4N"
}'{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"id": "usr_01M3PSWBPGS08FWV4NV7P9VNFN",
"externalId": "okta-00u9xK2mB7yLt4N",
"userName": "pat@acme.example",
"name": { "givenName": "Pat", "familyName": "Iyer", "formatted": "Pat Iyer" },
"displayName": "Pat Iyer",
"emails": [{ "value": "pat@acme.example", "type": "work", "primary": true }],
"active": true,
"title": "Support Engineer",
"department": "Customer Success",
"meta": {
"resourceType": "User",
"created": "2026-09-29T14:47:03.000Z",
"lastModified": "2026-09-29T14:47:03.000Z",
"version": "W/\"v1.0\"",
"location": "https://ulexid.com/api/v1/scim/v2/Users/usr_01M3PSWBPGS08FWV4NV7P9VNFN"
}
}One POST creates three things: the tenant-global user, an organization_membership with role: member in the directory's organization, and a user_directory_id link. It emits dsync.user.created and user.created.
A duplicate userName or externalId is 409 with scimType: "uniqueness". That is the mechanism IdP retries rely on; it is not an error you should suppress.
#Update
curl -sS -X PATCH "$BASE/scim/v2/Users/usr_01M3PSWBPGS08FWV4NV7P9VNFN" \
-H "Authorization: Bearer scim_7Bq4Nxf2Vk9Lc3MdT6hR8wS1yP5aG0eJ" \
-H "Content-Type: application/scim+json" \
-H 'If-Match: W/"v1.0"' \
-d '{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
"Operations": [
{ "op": "replace", "path": "name.givenName", "value": "Patricia" },
{ "op": "replace", "path": "department", "value": "Customer Experience" }
]
}'If-Match with a stale meta.version is 412 mutability. Re-read and re-apply. Do not drop the If-Match header; it is the only thing stopping a lost update when two sync runs overlap.
webhook payloads for dsync.user.updated carry data.previous_attributes with only the keys that changed, which is what you want for a change-data-capture pipeline.
#Deactivate
curl -sS -X DELETE "$BASE/scim/v2/Users/usr_01M3PSWBPGS08FWV4NV7P9VNFN" \
-H "Authorization: Bearer scim_7Bq4Nxf2Vk9Lc3MdT6hR8wS1yP5aG0eJ" -i | head -1HTTP/2 204 No Contentstatus → suspended
scim.active → false
sessions → all revoked, all organizations
refresh token families → all revoked
webhooks → dsync.user.deleted, user.deleted, user.suspended
audit → user.suspendedSCIM deprovisioning is tenant-wide. If a contractor is in two customer organizations and one customer deprovisions them, they lose access to both. That is the correct SCIM semantic, but it is a real support scenario. If you need per-customer removal, point the IdP at DELETE /organizations/{id}/members/{userId} through a provisioning workflow instead.
#5. Groups
curl -sS -X POST "$BASE/scim/v2/Groups" \
-H "Authorization: Bearer scim_7Bq4Nxf2Vk9Lc3MdT6hR8wS1yP5aG0eJ" \
-H "Content-Type: application/scim+json" \
-d '{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
"displayName": "Support",
"externalId": "okta-g-9k2mB7yLt4N",
"members": [
{ "value": "usr_01M3PSWBPGS08FWV4NV7P9VNFN", "display": "Pat Iyer" },
{ "value": "usr_01M3PSWCNRG3H18C3A2AHBRYRZ", "display": "Sam Rivera" }
]
}'{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
"id": "grp_01M3PSVED0M9RJTYH5AC72C253",
"externalId": "okta-g-9k2mB7yLt4N",
"displayName": "Support",
"members": [
{ "value": "usr_01M3PSWBPGS08FWV4NV7P9VNFN", "display": "Pat Iyer" },
{ "value": "usr_01M3PSWCNRG3H18C3A2AHBRYRZ", "display": "Sam Rivera" }
],
"meta": { "resourceType": "Group", "created": "2026-09-29T14:49:02.000Z", "lastModified": "2026-09-29T14:49:02.000Z", "version": "W/\"v1.0\"" }
}A SCIM group is a ulex group with source: "scim" and scim_id set to the externalId. PATCH /Groups/{id} with add/remove on members is incremental; PUT /Groups/{id} is a full replace. Okta and Entra both use PATCH correctly.
Group slugs emitted in the groups claim are derived from group_name_template (default {name}), slugified, and scoped to the organization. A group called "Support" in Acme and a group called "Support" in Globex are different groups with the same slug and different members.
#6. Bulk, for large directories
A 900-person directory is 900 POSTs at 3,000/min, which is fine, but it is 900 audit events and 900 webhook deliveries. Bulk is one request.
curl -sS -X POST "$BASE/scim/v2/Bulk" \
-H "Authorization: Bearer scim_7Bq4Nxf2Vk9Lc3MdT6hR8wS1yP5aG0eJ" \
-H "Content-Type: application/scim+json" \
-d '{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:BulkRequest"],
"failOnErrors": 1,
"Operations": [
{ "method": "POST", "path": "/Users", "bulkId": "alex", "data": { "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"], "userName": "alex@acme.example", "name": { "givenName": "Alex", "familyName": "Chen" }, "emails": [{ "value": "alex@acme.example", "primary": true }], "active": true } },
{ "method": "POST", "path": "/Users", "bulkId": "robin", "data": { "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"], "userName": "robin@acme.example", "name": { "givenName": "Robin", "familyName": "Vega" }, "emails": [{ "value": "robin@acme.example", "primary": true }], "active": true } },
{ "method": "POST", "path": "/Groups", "bulkId": "g1", "data": { "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"], "displayName": "Support", "members": [{ "value": "alex" }, { "value": "robin" }] } }
]
}'{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:BulkResponse"],
"Operations": [
{ "method": "POST", "bulkId": "alex", "version": "W/\"v1.0\"", "location": "/Users/usr_01M3PSWCNRG3H18C3A2AHBRYRZ", "status": "201" },
{ "method": "POST", "bulkId": "robin", "version": "W/\"v1.0\"", "location": "/Users/usr_01M3PSW0YRNEQQAP9T1JP9FC2Y", "status": "201" },
{ "method": "POST", "bulkId": "g1", "version": "W/\"v1.0\"", "location": "/Groups/grp_01M3PSVED0M9RJTYH5AC72C253", "status": "201" }
]
}| Rule | Value |
|---|---|
| Operations per request | 100 |
| Payload | 10 MiB |
failOnErrors | 0 runs everything and reports per operation; >= 1 aborts after the Nth failure |
bulkId | required, unique in the request, used to cross-reference group members |
Forward reference in members | error; reference a bulkId that appeared earlier |
| Over 100 | 413 scim_bulk_exceeded |
| Per-operation failure | appears in Operations[].response; the call's HTTP status is still 200 |
export async function bulkProvision(scimToken: string, rows: ProvisionRow[], orgId: string) {
const results = { created: 0, updated: 0, failed: 0, failures: [] as unknown[] };
for (let i = 0; i < rows.length; i += 100) {
const chunk = rows.slice(i, i + 100);
const res = await fetch(`${BASE}/scim/v2/Bulk`, {
method: "POST",
headers: { Authorization: `Bearer ${scimToken}`, "Content-Type": "application/scim+json" },
body: JSON.stringify({
schemas: ["urn:ietf:params:scim:api:messages:2.0:BulkRequest"],
failOnErrors: 0,
Operations: chunk.map((row) => ({
method: "POST",
path: "/Users",
bulkId: row.email,
data: {
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
userName: row.email,
name: { givenName: row.first_name, familyName: row.last_name },
displayName: `${row.first_name} ${row.last_name}`,
emails: [{ value: row.email, type: "work", primary: true }],
title: row.job_title ?? undefined,
department: row.department ?? undefined,
active: true,
},
})),
}),
});
const body = (await res.json()) as {
Operations: Array<{ status: number; bulkId?: string; response?: unknown }>;
};
for (const op of body.Operations) {
if (op.status >= 200 && op.status < 300) results.created++;
else {
results.failed++;
results.failures.push({ bulkId: op.bulkId, status: op.status, response: op.response });
}
}
}
return results;
}failOnErrors: 0 is right for a seed: you want to know about every bad row, not to stop at the first one. failOnErrors: 1 is right for a mirror, where a partial directory is worse than an unchanged one.
#7. Verifying the loop
# Did anything arrive?
curl -sS -G "$BASE/directories/dir_01M3PSVBF8038RK2MW2N263Q2B/users" \
-H "Authorization: Bearer $ULEX_API_KEY" --data-urlencode 'limit=5' | jq '.data[] | {id, email, status}'
# Did the events fire?
curl -sS -G "$BASE/audit-events" -H "Authorization: Bearer $ULEX_API_KEY" \
--data-urlencode 'action_prefix=directory.' --data-urlencode 'limit=10' | jq '.data[] | {action, outcome, timestamp}'
# Did the webhooks deliver?
curl -sS -G "$BASE/audit-events" -H "Authorization: Bearer $ULEX_API_KEY" \
--data-urlencode 'action_prefix=dsync.' --data-urlencode 'limit=10' | jq '.data[].action'#8. Rate limits and retries
| Bucket | Limit |
|---|---|
| SCIM requests | 3,000 / minute / bearer token |
| Bulk operations | 100 / request |
count | 200, clamped not errored |
| Filter complexity | 1 attribute path, 4 boolean operators |
On 429, honour Retry-After. On 5xx with retryable: true, back off exponentially with jitter. IdPs retry on their own schedule — Okta retries for hours — so your endpoint must be idempotent, which it is: a duplicate POST /Users is a 409, not a duplicate user.
#9. Troubleshooting matrix
| Symptom | Cause | Fix |
|---|---|---|
| Okta "Test connection" fails immediately | wrong token, or directory not active | re-read the token from GET /directories/{id}/scim; check state |
409 uniqueness on every push | userName already exists, created by a different route | filter by externalId instead of userName, or reconcile before pushing |
412 mutability on every update | stale meta.version in If-Match | re-read the user, then patch with the fresh version |
400 invalidFilter | Entra sends externalId eq "..." where the attribute does not exist | map it, or set the attribute to be emitted |
| Users provisioned but cannot log in | organization is sso_only and has no active connection | activate a connection, or set sso_only: false |
| Deprovisioning removed access to another customer | SCIM deprovision is tenant-wide | expected; use membership removal for per-customer scope |
413 scim_bulk_exceeded | over 100 operations | chunk at 100 |
| Nothing arriving at all | inbound_scim_enabled: false | PATCH /directories/{id} with true |