Import Device Token API

Import Device Token API

Import Device Tokens

CleverTap enables developers to import an existing device token to a user’s device in a user’s profile.

Request Authentication

Every request to the API should include your CleverTap Account ID and CleverTap Account Passcode in the request header keyed with X-CleverTap-Account-Id and X-CleverTap-Passcode, respectively. Content-Type header must be specified as application/json.

Endpoint

A request to upload device tokens to a User Profile is an HTTP URL of the following form:

POST https://api.clevertap.com/1/upload

Payload

JSON-formatted request with the following parameters

Required parameters

type – set to ‘token’ for updating an Tokens. Must be String
tokenData – JSON keys and values to be updated. See example payload below
objectId – Can be used to identify a unique user by their CleverTap Global Object ID. Must be String

Note : for updating google chrome tokens, below mentioned additional JSON keys are also required
keys – JSON object, retrieved from google endpoint response at the time of registering WebPush subscription (Example Below)

Payload Structure for iOS/Android/Windows (mobile devices)

{
    "d": [
        {
            "type": "token",
            "tokenData": {
                "id": <Device Token>,
                "type": apns/gcm/fcm/wns/mpns
            },
            "objectId": <ClevertapId/GUID>
        }
    ]
}
copy Copied

Payload Structure for WebPush (Chrome)

{
    "type": "token",
    "tokenData": {
        "id": <DeviceToken>,
        "type": "chrome",
        "keys": {
            "p256dh": <>,
            "auth": <>
        }
    },
    "objectId": <ClevertapId/GUID>
}
copy Copied

Example payload

{
    "d": [
        {
            "type": "token",
            "tokenData": {
                "id": "frfsgvrwe:APfdsafsgdfsgghfgfgjkhfsfgdhjhbvcvnetry767456fxsasdf",
                "type": "chrome",
                "keys": {
                    "p256dh": "BLc4xRzKlKORKWlbdgFaBrrPK3ydWAHo4M0gs0i1oEKgPpWC5cW8OCzVrOQRv-1npXRWk8udnW3oYhIO4475rds=",
                    "auth": "5I2Bu2oKdyy9CwL8QVF0NQ=="
                }
            },
            "objectId": "QBOpVJZmKilRAzfaiVS86Tovxm75lHxg"
        },
        {
            "type": "token",
            "tokenData": {
                "id": "dYfuuBmHLGI:APA91bEfAq1b6NAmz0uhUbVxwSLqgKF25zDb7vhgajzS-bOAEUKekH_jbzO5oU1Qip-ZLvDpwKccxAxVNjC3rUUJnFTKDUiBcF9AtuG03_PRfjoUxLKHMR9qykK22SiubrLirNzQtNnO",
                "type": "fcm"
            },
            "objectId": "__gc4grg4053N1eYkW6OBH71jhFev7b1iP"
        },
        {
            "type": "token",
            "tokenData": {
                "id": "frfsgvrwe:APfdsafsgdfsgghfgfgjkhfsfgdhjhbvcvnetry767456fxsasdf",
                "type": "gcm"
            },
            "objectId": "__QlXHaDHBZxZPLEMpPo6VvwdZ7FnbGvWA"
        },
        {
            "type": "token",
            "tokenData": {
                "id": "frfsgvrwe:APfdsafsgdfsgghfgfgjkhfsfgdhjhbvcvnetry767456fxsasdf",
                "type": "apns"
            },
            "objectId": "-HwB9gZWb3RcKhXCQ222FhAhkjeYQs0Hj"
        },
        {
            "type": "token",
            "tokenData": {
                "id": "frfsgvrwe:APfdsafsgdfsgghfgfgjkhfsfgdhjhbvcvnetry767456fxsasdf",
                "type": "wns"
            },
            "objectId": "~9XrS4Dy6GsnDbdX98Ijs63kEtJDQbhJA"
        },
        {
            "type": "token",
            "tokenData": {
                "id": "frfsgvrwe:APfdsafsgdfsgghfgfgjkhfsfgdhjhbvcvnetry767456fxsasdf",
                "type": "mpns"
            },
            "objectId": "~y9MqjkDGRfbzwwH8fZI6LIXgTKaEPxHr"
        }
    ]
}
copy Copied

Error Codes

530 : Invalid ‘objectId’
531 : Invalid token data
532 : Token ‘id’ is not present
533 : Token ‘type’ is not present
534 : Token ‘type’ is not valid for ‘objectId’
535 : Invalid token data

Limitations and Constraints

Device token can be updated against CleverTapId (objectId/guid) and not against an email ID or user’s identity in a profile. If given profile already has a token, it won’t be updated and an error will be reported into Live Error Stream.

Maximum 100 records may be sent per API call. The calls to the endpoint are synchronous. We recommend you make a single call from your server at a time, wait for the response before making another API request.