Create Token

Generate a new token for your account.

POST /tokens/create

Parameters

Parameter Type Required Description
type string The type of the token, which can be used to classify tokens for different purposes.
refId string A reference identifier for the token, which can be used to associate the token with a specific entity, such as a user.
payload string | obj The payload of the token, which can be a string or an object. This can be used to store additional information related to the token, such as user details or permissions.
uses number The number of times the token has been used. This is not usually set when creating a token. This value is auto-incremented when the token is redeemed.
maxUses number The maximum number of times the token can be used before it becomes invalid.
expiresAt Date The date and time when the token expires. After this time, the token is no longer valid.

Returns

A token object

import axios from 'axios';

const props = {
    type: 'session',
    refId: 'some-object-id',
    payload: {hello: 'world'},
    uses: 0,
    maxUses: 10,
    expiresAt: new Date('2050-01-01')
}

const config = {headers: {authorization: API_KEY_ID}}

let {status, data} = await axios.post(
    'https://api.x-tkn.com/tokens/create',
    props,
    config
)

let token = data

Delete Token

Permanently delete token from your account.

DEL /tokens/:tokenId

Parameters

Parameter Type Required Description
tokenId string The unique identifier of the token to be deleted

Returns

void

import axios from 'axios';

const tokenId = 'some-token-id'

const config = {headers: {authorization: API_KEY_ID}}

await axios.delete(
    'https://api.x-tkn.com/tokens/' + tokenId,
    config
)

List Tokens

Extends the expiration date of a token by the given amount of time.

POST /tokens/list

Parameters

Parameter Type Required Description
where object The unique identifier of the token to be deleted
orderBy object The order in which the tokens are returned. Default: {createdAt: 'desc'}.
skip number The number of tokens to skip before returning the first token. Default: 0.
take number The number of tokens to return. Default: 100.

Returns

{count: number, tokens: token[]}

import axios from 'axios';

const req = {
    where: {
        refId: 'some-object-id',
        type: 'session'
    },
    orderBy: {createdAt: 'desc'},
    skip: 0,
    take: 100
}

const config = {headers: {authorization: API_KEY_ID}}

const {count, tokens} = await axios.post(
    'https://api.x-tkn.com/tokens/list',
    req,
    config
)

Read Token

This method returns a token object for the specified token id.

GET /tokens/:tokenId

Parameters

Parameter Type Required Description
tokenId string The unique identifier of the token to be deleted

Returns

A token object

import axios from 'axios';

const tokenId = 'some-token-id'

const config = {headers: {authorization: API_KEY_ID}}

const token = await axios.get(
    'https://api.x-tkn.com/tokens/' + tokenId,
    config
)

Redeem Token

This method returns a token object for the specified token id or short code. It is primarily used for limited use tokens. Calling this method will increment the token's use count.

  • If the token is expired, it will return null.
  • If the token has reached it's maximum uses, it will return null.
  • If the token has been revoked, it will return null.
  • If the short code is provided but does not match the one assigned to the token, it will return null.

PATCH /tokens/:tokenId_or_shortCode/redeem

Parameters

Parameter Type Required Description
tokenId or shortCode string The unique identifier of the token to be redeemed.

Returns

A token object

import axios from 'axios';

const tokenId = 'some-token-id--or--short-code'

const config = {headers: {authorization: API_KEY_ID}}

const token = await axios.patch(
    'https://api.x-tkn.com/tokens/' + tokenId + '/redeem',
    data,
    config
)

Revoke Token

This method revokes the specified token. A revoked token will no longer be valid.

PATCH /tokens/:tokenId/revoke

Parameters

Parameter Type Required Description
tokenId string The unique identifier of the token to be deleted

Returns

A token object

import axios from 'axios';

const tokenId = 'some-token-id'

const config = {headers: {authorization: API_KEY_ID}}

const token = await axios.patch(
    'https://api.x-tkn.com/tokens/' + tokenId + '/revoke',
    config
)

Revoke Tokens

Revokes many tokens that match the specified type or refId

PATCH /tokens/revoke

Parameters

Parameter Type Required Description
type string The type of the token, which can be used to classify tokens for different purposes.
refId string A reference identifier for the token, which can be used to associate the token with a specific entity, such as a user.

Returns

A token object

import axios from 'axios';

const data = {
    refId: 'some-token-id',
    type: 'some-type'
}

const config = {headers: {authorization: API_KEY_ID}}

const token = await axios.post(
    'https://api.x-tkn.com/tokens/revoke',
    data,
    config
)

Update Token

This method updates the specified token. The following properties can be updated: type, refId, payload, uses, maxUses and expiresAt

PATCH /tokens/:tokenId/update

Parameters

Parameter Type Required Description
type string The type of the token, which can be used to classify tokens for different purposes.
refId string A reference identifier for the token, which can be used to associate the token with a specific entity, such as a user.
payload string | obj The payload of the token, which can be a string or an object. This can be used to store additional information related to the token, such as user details or permissions.
uses number The number of times the token has been used. This is not usually set when creating a token. This value is auto-incremented when the token is redeemed.
maxUses number The maximum number of times the token can be used before it becomes invalid.
expiresAt Date The date and time when the token expires. After this time, the token is no longer valid.

Returns

A token object

import axios from 'axios';

const tokenId = 'some-token-id'

const config = {headers: {authorization: API_KEY_ID}}

const token = await axios.patch(
    'https://api.x-tkn.com/tokens/' + tokenId + '/revoke',
    config
)