Manage API Tokens
    • PDF

    Manage API Tokens

    • PDF

    Article summary

    The following API methods help you to manage API tokens and perform relevant operations.


    1. Retrieve API Tokens

    The GET method returns all the API tokens in the system.

    GET{{url}}/api/token

    Request Example

    An example GET request for retrieving all the API tokens is shown here.

    curl --location --request GET '{{url}}/api/token' \
    --header 'Authorization: TOKEN {{apiToken}}'

    Response Example 

    An example response of the GET request for retrieving all the built-in reports is shown here.

    Status: 200 OK

    [
        {
            "id": "091ebeiaxuk4455qo0cd",
            "name": "Token1",
            "expiresOn": "2020-11-07T13:50:03Z",
            "createdOn": "2020-09-15T10:34:34Z",
            "type": "DEFAULT",
            "status": "Active",
            "lastAccessed": "2020-10-08T13:50:03Z",
            "assignedTo": null,
            "createdBy": "null"
        },
        {
            "id": "0een5vgj6jhfavcunap4",
            "name": "Token2",
            "expiresOn": "2020-11-06T14:43:08Z",
            "createdOn": "2020-10-07T14:43:08Z",
            "type": "DEFAULT",
            "status": "Active",
            "lastAccessed": "2020-10-07T14:43:08Z",
            "assignedTo": null,
            "createdBy": null
        }
    ]

    2. Create an API Token

    The POST method creates a new API token with full administrator privileges. It takes a name as the parameter and returns the API token. 

    Note:

    The API token is returned only once. Please copy and keep it in a secure location. If you lose the token you will have to generate a new token again.


    POST{{url}}/api/token

    Request Parameters

    The request parameters used in this method are shown in the following table:

    ParameterDescriptionData TypeRequired
    nameThe name of the token.stringOptional

    tokenExpirationDays

    The tokenExpirationDays represent the number of days in which the token would expire since last used.

    The token expiration days can be any value between 1 and 90 days.

    string

    Optional

    Request Example

    An example POST request for creating an API token is shown here.

    curl --location --request POST '{{url}}/api/token' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: TOKEN {{token}}' \
    --data-raw '{
    	"name" : "admin-token1",
        "tokenExpirationDays" : 60
    }'

    Response Example 

    An example response of the POST request for creating an API token is shown here.

    Status: 201 Created
    {
      "id": "bs2mmsm47o62lglhixab",
      "name": "admin-token1",
      "expiresOn": "2021-02-14T05:31:26Z",
      "createdOn": "2020-12-16T05:31:26Z",
      "type": "DEFAULT",
      "tokenExpirationDays": 60,
      "lastAccessed": "2020-12-16T05:31:26Z",
      "status": "Active",
      "assignedTo": null,
      "token": "AAAA=",
      "createdBy": "user1"
    }

    3. Revoke a Token

    The DELETE method revokes a token for the token id provided in the request path. 

    Use the Get tokens API call to retrieve the id of the token that should be revoked.

    DELETE{{url}}/api/token/{{tokenID}}

    Request Example

    An example DELETE request for revoking a token is shown here.

    curl --location --request DELETE '{{url}}/api/token/{{tokenID}}' \
    --header 'Authorization: TOKEN {{apiToken}}'

    Response Example 

    An example response of the DELETE request for revoking a token is shown here.

    Status: 200 OK
    Successfully revoked token.

    4. Update a Token

    The PUT method updates an API Token for the token ID provided in the request path. 

    PUT{{url}}/api/token/{{tokenID}}

    Request Parameters

    The request parameters used in this method are shown in the following table:

    ParameterDescriptionData TypeRequired
    IDThe ID of the token.stringMandatory
    nameThe name of the token.stringMandatory

    tokenExpirationDays

    The number of days in which token would expire since it was last used.

    The token expiration days can be any value between 1 day and 90 days.

    string

    Mandatory

    The method returns the API token in the response only once.

    Request Example

    An example PUT request for updating a token is shown here.

    curl --location --request PUT '{{url}}/api/token/bs2mmsm47o62lglhixab' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: TOKEN {{token}}' \
    --data-raw '{
    	"name" : "admin-token2",
        "tokenExpirationDays" : 90
    }'

    Response 

    Note:

    This request does not return a response body.


    5. Update Token Expiration Days

    The PATCH method updates the API token expiration days for the token ID provided in the request path. 

    PATCH{{url}}/api/token/{{tokenID}}

    Request Parameters

    The request parameters used in this method are shown in the following table:

    ParameterDescriptionData TypeRequired
    IDThe ID of the token.stringMandatory

    tokenExpirationDays

    The tokenExpirationDays represent the number of days in which the token would expire since last used.

    The token expiration days can be any value between 1 and 90 days.

    string

    Mandatory

    Request Example

    An example PATCH request for updating the API token expiration days is shown here.

    curl --location --request PATCH '{{url}}/api/token/bs2mmsm47o62lglhixab' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: TOKEN {{token}}' \
    --data-raw '{
        "tokenExpirationDays" : 90
    }'

    Response 

    Note:

    This request does not return a response body.








    Was this article helpful?