Map user
POST
/api/v1/external/consents/map-userWhen 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.
| Header | Type | Required | Description |
|---|---|---|---|
X-Org-Id | string | Yes | Your organization slug |
X-API-Key | string | Yes | Your tenant API key |
Body
| Field | Type | Required | Description |
|---|---|---|---|
anonymousId | string | Yes | The anonymous or session-based user ID to transfer records from |
authenticatedUserId | string | Yes | The authenticated user ID to transfer consent records to |
metadata | object | No | Optional key-value pairs to attach to the mapping event |
Response
200 OK
| Field | Type | Description |
|---|---|---|
success | boolean | true if the operation completed without error |
mapped_count | integer | Number of consent log entries transferred. 0 means no records existed under anonymousId — this is not an error. |
anonymous_id | string | The anonymous ID that was provided in the request |
authenticated_user_id | string | The authenticated user ID that records were transferred to |
message | string | A human-readable summary of the operation result |
Errors
| Status | Description |
|---|---|
400 | X-Org-Id could not be resolved |
401 | X-API-Key is invalid or missing |
403 | API key lacks the admin scope |
422 | anonymousId or authenticatedUserId is missing or fails validation |
500 | Internal server error |
Example
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"}