POST /token/generate
Requests a UID2 token generated from a user's DII (email address or phone number). If the DII is valid, and the user has not opted out of UID2, this operation returns a UID2 token and associated values.
Used by: This endpoint is used mainly by publishers.
The optout_check
parameter, required with a value of 1
, checks whether the user has opted out.
Rather than calling this endpoint directly, you could use one of the SDKs to manage it for you. For a summary of options, see SDKs: Summary.
Request Format
POST '{environment}/v2/token/generate'
For authentication details, see Authentication and Authorization.
Here's what you need to know about sending requests to this endpoint:
- To ensure that the API key used to access the service remains secret, UID2 tokens must be generated only on the server side after authentication.
- You must encrypt all requests using your secret. For details, and code examples in different programming languages, see Encrypting Requests and Decrypting Responses.
Path Parameters
Path Parameter | Data Type | Attribute | Description |
---|---|---|---|
{environment} | string | Required | Testing (integration) environment: https://operator-integ.uidapi.com Production environment: The best choice depends on where your users are based. For information about how to choose the best URL for your use case, and a full list of valid base URLs, see Environments. Notes:
|
Unencrypted JSON Body Parameters
You must include only one of the following four conditional parameters, plus the required optout_check
parameter with a value of 1
, as key-value pairs in the JSON body of the request when encrypting it.
Body Parameter | Data Type | Attribute | Description |
---|---|---|---|
email | string | Conditionally Required | The email address for which to generate tokens. |
email_hash | string | Conditionally Required | The Base64-encoded SHA-256 hash of a normalized email address. |
phone | string | Conditionally Required | The normalized phone number for which to generate tokens. |
phone_hash | string | Conditionally Required | The Base64-encoded SHA-256 hash of a normalized phone number. |
optout_check | number | Required | Checks whether the user has opted out. Include this parameter with a value of 1 . |
Request Examples
To ensure that the API key used to access the service remains secret, the POST /token/generate
endpoint must be called from the server side, unlike POST /token/refresh which does not require using an API key. If you want to generate tokens on the client side, see Client-Side Integration Options (for web-based implementations) or UID2 Client-Side Integration Guide for Mobile.
The following are unencrypted JSON request body examples for each parameter, one of which you should include in your token generation requests:
{
"email": "username@example.com",
"optout_check": 1
}
{
"email_hash": "tMmiiTI7IaAcPpQPFQ65uMVCWH8av9jw4cwf/F5HVRQ=",
"optout_check": 1
}
{
"phone": "+12345678901",
"optout_check": 1
}
{
"phone_hash": "wdN1alhrbw1Bmz49GzKGdPvGxLhCNn7n3teAOQ/FSK4=",
"optout_check": 1
}
Here's an encrypted token generation request example for an email hash:
echo '{"email_hash": "tMmiiTI7IaAcPpQPFQ65uMVCWH8av9jw4cwf/F5HVRQ=","optout_check":1}' | python3 uid2_request.py https://prod.uidapi.com/v2/token/generate [Your-Client-API-Key] [Your-Client-Secret]
For details, and code examples in different programming languages, see Encrypting Requests and Decrypting Responses.
Decrypted JSON Response Format
The response is encrypted only if the HTTP status code is 200. Otherwise, the response is not encrypted.
This section includes the following sample responses: