Skip to content

Map user

POST /api/v1/external/consents/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.

Authentication

Both headers are required.

HeaderTypeRequiredDescription
X-Org-IdstringYesYour organization slug
X-API-KeystringYesYour tenant API key

Body

FieldTypeRequiredDescription
anonymousIdstringYesThe anonymous or session-based user ID to transfer records from
authenticatedUserIdstringYesThe authenticated user ID to transfer consent records to
metadataobjectNoOptional key-value pairs to attach to the mapping event

Response

200 OK

FieldTypeDescription
successbooleantrue if the operation completed without error
mapped_countintegerNumber of consent log entries transferred. 0 means no records existed under anonymousId — 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
400X-Org-Id could not be resolved
401X-API-Key is invalid or missing
403API key lacks the admin scope
422anonymousId or authenticatedUserId is missing or fails validation
500Internal server error

Example

Terminal window
curl --request POST \
--url 'https://truapi-dev.truconsent.io/api/v1/external/consents/map-user' \
--header 'X-Org-Id: acme' \
--header 'X-API-Key: tck_live_xxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
"anonymousId": "sess_a3f9b12c4d8e",
"authenticatedUserId": "usr_7f3a9b21",
"metadata": {
"login_method": "google_oauth"
}
}'
{
"success": true,
"mapped_count": 2,
"anonymous_id": "sess_a3f9b12c4d8e",
"authenticated_user_id": "usr_7f3a9b21",
"message": "Successfully mapped 2 consent logs"
}