logo
Desarrollo
Buscar
Set User ID

Set User ID

GPTBots supports developers in setting a unique identity ID (UserId) for Agent users across different channels (e.g., websites, apps, LiveChat). This UserId enables user identity association across channels, facilitating cross-channel user identity merging, business queries via Tools, and maintenance of user attributes and chat records. Specific application scenarios for UserId include:

  • Tools: When the AI Agent calls Tools to make requests to the developer's business API, the UserId will be included in the header, allowing developers to identify the user.
  • User Attributes: After the developer sets the UserId, user attribute information will be associated with this UserId.
  • Conversation Logs: After the developer sets the UserId, the user's conversation log records with the Agent will be attributed to this UserId.
  • Event Callbacks: After the developer sets the UserId, event callbacks generated within iframes/widgets and reported to GA4/webhooks will carry this information.

⚠️ The User ID (UserId) should be the unique identifier for a user within the developer's business system. This UserId can be used to query business data such as the user's VIP level, user tags, and order information.

Set User ID

This API allows developers to set the User ID using a combination of anonymous ID + conversation type + source ID to manage user identity information.

Request Method

POST

Endpoint

https://api.${endpoint}/v1/user/set-userid

Request

Request Example

curl -X POST 'https://api.${endpoint}/v1/user/set-userid' \ -H 'Authorization: Bearer ${token}' \ -H 'Content-Type: application/json' \ -d '{ "user_id": "67b58121035e5b152b0419ee", "anonymous_ids": [ { "anonymous_id": "6a0dnyvi3jc32flk7enw", "conversation_type": "SHARE" }, { "anonymous_id": "6a0dnyvi3jc32flk7enw", "conversation_type": "TELEGRAM", "source_id": "bot_029392" } ] }'
                      
                      curl -X POST 'https://api.${endpoint}/v1/user/set-userid' \
-H 'Authorization: Bearer ${token}' \
-H 'Content-Type: application/json' \
-d '{
    "user_id": "67b58121035e5b152b0419ee",
    "anonymous_ids": [
        {
            "anonymous_id": "6a0dnyvi3jc32flk7enw",
            "conversation_type": "SHARE"
        },
        {
            "anonymous_id": "6a0dnyvi3jc32flk7enw",
            "conversation_type": "TELEGRAM",
            "source_id": "bot_029392"
        }
    ]
}'

                    
Este bloque de código en una ventana flotante

A user_id can be bound to a maximum of 100 anonymous_ids. If this limit is exceeded, the binding with the earliest updateTime will be automatically removed.
Developers can obtain the current user's anonymous ID by referencing anonymous_id in global variables, and the conversation type via conversation_type.

Request Headers

Field Type Description
Authorization Bearer ${token} Use Authorization: Bearer ${token} for authentication. Please obtain your token from the API Key page.
Content-Type application/json Data type, value is: application/json.

Request Body

Parameter Type Description Required
user_id string Developer-defined User ID true
anonymous_ids array A list of anonymous IDs generated by the GPTBots platform, typically based on unique identifiers from third-party platforms. Can be obtained from anonymous_id in Agent global variables. true
anonymous_ids[].anonymous_id string Anonymous ID true
anonymous_ids[].conversation_type string The source platform of the anonymous ID, equivalent to the platform in 'Agent-Integration', such as WHATSAPP, LINE, etc. Can be obtained from conversation_type in the user overview. true
anonymous_ids[].source_id string Channel ID from the conversation source platform. For example, if integrated with TELEGRAM and two TG Bots are added, each Bot will have its own Source ID. false

Binding Logic Description:

  1. The binding relationship is uniquely determined by the combination of anonymous_id + conversation_type + source_id.
  2. If this combination is already bound to the current user_id, only the binding time (updateTime) will be updated.
  3. If this combination is not bound to any user_id, a new binding relationship will be created.
  4. If this combination is already bound to another user_id, the old binding relationship will be unbound first, and then bound to the current user_id.
  5. If the number of bindings for a single user_id exceeds 100, the binding record with the earliest updateTime will be automatically deleted.

Response

Response Body

{ "code": 0, "message": "OK", "data": { "user_id": "67b58121035e5b152b0419ee", "anonymous_ids": [ { "anonymous_id": "6a0dnyvi3jc32flk7enw", "conversation_type": "SHARE", "source_id": null }, { "anonymous_id": "6a0dnyvi3jc32flk7enw", "conversation_type": "TELEGRAM", "source_id": "bot_029392" } ] } }
                      
                      {
    "code": 0,
    "message": "OK",
    "data": {
        "user_id": "67b58121035e5b152b0419ee",
        "anonymous_ids": [
            {
                "anonymous_id": "6a0dnyvi3jc32flk7enw",
                "conversation_type": "SHARE",
                "source_id": null
            },
            {
                "anonymous_id": "6a0dnyvi3jc32flk7enw",
                "conversation_type": "TELEGRAM",
                "source_id": "bot_029392"
            }
        ]
    }
}

                    
Este bloque de código en una ventana flotante

Successful Response

Field Type Description
user_id string User ID
anonymous_ids array All anonymous IDs currently bound to this user ID and their conversation types
anonymous_ids[].anonymous_id string Anonymous ID
anonymous_ids[].conversation_type string The enumeration value of the conversation type, equivalent to the platform in "Agent-Integration"
anonymous_ids[].source_id string Channel ID from the conversation source platform. For example, if integrated with TELEGRAM and two TG Bots are added, each Bot will have its own Source ID.

Error Response

Field Type Description
code int Error code
message string Error message

Status Codes

Status Code Description
200 Success
400 Invalid parameters
401 Unauthorized
403 Forbidden
500 Server error