Skip to main content

user.hierarchy_changed

A user's managerId changed (within-agency reshuffle or cross-agency move). Emitted scoped to the new owning agency.

Category: User Lifecycle

Emitted when: After the managerId write commits in Better Auth AND the old/new managerIds differ (no-op writes are short-circuited).

Envelope

Every delivery wraps the event-specific data block in the canonical envelope documented on the webhook overview page. The body carries SIX keys; the HMAC signature is delivered as the X-Webhook-Signature request header on the inbound POST to your endpoint (NOT as a body field; including it in the body would make the HMAC a function of its own output).

FieldTypeDescription
event_idstringULID; globally unique. Safe to persist as the dedup key.
event_typestringAlways user.hierarchy_changed for this event.
api_versionstringPayload schema version (YYYY-MM-DD).
timestampintegerUnix epoch seconds at dispatch time.
noncestringULID; unique per delivery, used for replay rejection.
dataobjectEvent-specific payload (see below).

Delivery also sets three HTTP headers on the inbound POST:

HeaderMeaning
X-Webhook-Event-IdMirrors event_id; cheaper than parsing the body to dedup.
X-Webhook-TimestampMirrors timestamp for replay-window checks.
X-Webhook-Signaturesha256=<hex> HMAC over timestamp.body.

Data schema

FieldTypeRequiredDescription
agency_idstringyesPost-change agency id
previous_agency_idstring | nullnoPre-change agency id; None when the user had no prior resolvable agency.
user_idstringyesUser Id
emailstringyesEmail at the time of the change
role"media_agency" | "team" | "broker" | "agent" | "assistant" | "viewer"yesRole
old_manager_idstring | nullnoOld Manager Id
new_manager_idstring | nullnoNew Manager Id
changed_atstringyesChanged At
changed_bystringyesActor token: 'user:' for dashboard admin action, 'admin:' for reserved admin-tool/background paths.

Sample payload

The sample below is a live fixture. Feed the exact body bytes shown plus the timestamp into the HMAC-SHA256 recipe from the webhook overview using the documented test-vector secret (test_secret_001 ) and you will recover the signature header value printed below.

Body (delivered as the HTTP request body):

{
"event_id": "evt_7W3QNQ5PCEFE67B0RNMJH1J1KY",
"event_type": "user.hierarchy_changed",
"api_version": "2026-04-17",
"timestamp": 1745339401,
"nonce": "2D437HTXC48NGYZ1GQVX5RCQV4",
"data": {
"agency_id": "user_01HXAGENCY0000000000000",
"previous_agency_id": "01HX5Y7Z2M3N4P5Q6R7S8T9U0V",
"user_id": "user_01HXAGENCYUSER000000000",
"email": "user@example.com",
"role": "agent",
"old_manager_id": "01HX5Y7Z2M3N4P5Q6R7S8T9U0V",
"new_manager_id": "01HX5Y7Z2M3N4P5Q6R7S8T9U0V",
"changed_at": "2026-05-29T12:00:00Z",
"changed_by": "apikey:key_01HXAPIKEY000000000000"
}
}

Signature header (delivered as X-Webhook-Signature on the same request):

sha256=fb043545706f2507e0365f1686a234678f187aca77b4f7749bacbce3af2d347d

Retry behaviour

Failed deliveries retry on the sequence 2, 4, 8, 16, 32 seconds (five attempts plus the initial call for a total of six over approximately 62 seconds of wall clock). After the final attempt the delivery lands in the dead-letter queue and the dashboard operator can replay it from Settings > API Keys > Webhook Endpoint > Deliveries. See the webhook overview for the full rules.

Verification

Every receiver MUST verify the X-Webhook-Signature header using the recipe in the webhook overview. Rejecting deliveries whose timestamp is more than 5 minutes off your wall clock (after NTP correction on your side) or whose nonce has already been consumed in the last 10 minutes is part of the contract.