User Attribute APIs

Last updated: 2021-04-25 11:21:43

    API Description

    Request method: POST.

    Service URL/v3/device/set_custom_attribute
    

    API service URLs correspond to service access points one by one. Please select the service URL corresponding to the service access point of your application.

    Feature: this API is used to manage personalized attributes at the token level, including creation, deletion, update, and query operations.

    Parameter Description

    Request parameters

    Parameter Required Type Description
    cmd Yes Integer Operation type:
  • 1: adding an attribute.
  • 2: updating an attribute.
  • 3: deleting an attribute.
  • 4: deleting all attributes.
  • 5: querying attributes.
  • token Yes String Unique ID assigned to each device by TPNS.
  • Suggestions on getting TPNS token (Android)
  • Suggestions on getting TPNS token (iOS)
  • attributeInfo Yes (when cmd is 1, 2, or 3) Map Attribute details. See the description of the attributeMap parameter below.
    attributeMap Yes (when cmd is 1, 2, or 3) Map Attribute details:
  • key indicates the attribute name and can contain up to 50 bytes.
    Note: you should have created an attribute in the TPNS console > Toolbox > User Attribute Management; otherwise, this parameter will be filtered out, and invalidAttribute will be returned.
  • value indicates the attribute value and can contain up to 50 bytes.
  • Response parameters

    Parameter Returned Type Description
    retCode Yes Integer Error code. For more information, please see Server-Side Error Codes.
    errMsg Yes String Error message when an error occurs in the request.
    attributeInfo Yes (when cmd is 5) Map Attribute details.
    invalidAttribute Yes (when the attribute is invalid) Array Details of the invalid attribute.

    Samples

    Adding an attribute

    Sample request

    Add three attributes to a token.

    {
        "cmd": 1,
        "token": "04cac74a714f61bf089987a986363d88****",   
        "attributeInfo": {
             "attributeMap": {
                "age": "100",
                "name": "Ming",
                "high": "2.66"
            }
        }
    }
    
    

    Sample response

    {
        "retCode": 0,
        "errMsg": "success",
        "invalidAttribute": [
            "high"   // The corresponding key value does not exist in the console
        ]
    }
    

    Updating an attribute

    Sample request

    Update the value of the name attribute to workman.

    {
        "cmd": 2,    
        "token": "04cac74a714f61bf089987a986363d88****",
        "attributeInfo": {
             "attributeMap": {
                "name": "workman"   
            }
        }
    }
    
    
    

    Sample response

    {
        "retCode": 0,
        "errMsg": "success"
    }
    

    Deleting an attribute

    Sample request

    Delete the workman value of the name attribute.

    {
        "cmd": 3,    
        "token": "04cac74a714f61bf089987a986363d88****",
        "attributeInfo": {
             "attributeMap": {
                "name": "workman"  
            }
        }
    }
    
    
    

    Sample response

    {
        "retCode": 0,
        "errMsg": "success"
    }
    

    Deleting all attributes

    Sample request

    Delete all attributes of a token.

    {
        "cmd": 4,    
        "token": "04cac74a714f61bf089987a986363d88****"  
    
    }
    

    Sample response

    {
        "retCode": 0,
        "errMsg": "success"
    }
    

    Querying attributes

    Sample request

    Query the attribute details of a token.

    {
        "cmd": 5,    
        "token": "04cac74a714f61bf089987a986363d88****"
    
    }
    

    Sample response

    {
        "retCode": 0,
        "errMsg": "success",
        "attributeInfo": {
            "attributeMap": {
                "nickname": "workman"
            }
        }
    }