Skip to content

Map user

POST /consent/map-user

When a user interacts with your application before logging in, truConsent records consent under a temporary anonymous or session-based ID. Once the user authenticates, call this endpoint to transfer all of those consent records to their permanent authenticated user ID. This preserves the full consent history across the login boundary.

A typical integration records consent with a session token as the userId, then calls this endpoint at login to reassign those records to the authenticated user ID from your identity provider.

Headers

HeaderTypeRequiredDescription
X-API-KeystringYesYour tenant API key

Body

FieldTypeRequiredDescription
anonymousIdstringYesThe anonymous or session-based user ID to transfer records from. All consent log entries where data_principal_id matches this value will be reassigned.
authenticatedUserIdstringYesThe authenticated user ID to transfer consent records to.
metadataobjectNoOptional key-value pairs to attach to the mapping event. Merged into the metadata field of each transferred consent log entry.

Response

200 OK

FieldTypeDescription
successbooleantrue if the operation completed without error
mapped_countintegerNumber of consent log entries transferred. A value of 0 means no records were found for the given anonymous ID — this is not an error.
anonymous_idstringThe anonymous ID that was provided in the request
authenticated_user_idstringThe authenticated user ID that records were transferred to
messagestringA human-readable summary of the operation result

Errors

StatusDescription
422anonymousId or authenticatedUserId is missing or fails validation
500Internal server error

Example

Terminal window
curl --request POST \
--url 'https://{your-truConsent-endpoint}/consent/map-user' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: tck_live_xxxxxxxxxxxx' \
--data '{
"anonymousId": "sess_a3f9b12c4d8e",
"authenticatedUserId": "usr_7f3a9b21",
"metadata": {
"login_method": "google_oauth",
"session_start": "2026-04-21T09:00:00Z"
}
}'
{
"success": true,
"mapped_count": 2,
"anonymous_id": "sess_a3f9b12c4d8e",
"authenticated_user_id": "usr_7f3a9b21",
"message": "Successfully mapped 2 consent logs"
}