Tyk v2.2 Documentation Components

HomeTyk v2.2 Documentation ComponentsTutorial: Create an API Token Without GUI (Cloud)

Tutorial: Create an API Token Without GUI (Cloud)

To create an API token, we will need the API ID that we wish to grant the token access to. Creating the token is then a very simple API call to the endpoint.

You will also need your own API Key, to get these values:

  1. Click on “System Management” -> “Users”.
  2. In the users list, click “Edit” for your user.
  3. The API key is labelled “Tyk Dashboard API Access Credentials”, copy this somewhere you can reference it.
  4. Click on “System Management” -> “APIs”.
  5. The API ID is next to your API name, copy this somewhere for reference too.

Once you have these values, you can use them to access the dashboard API, the below curl command will generate a token for one of your APIs, remember to replace {API-KEY}, {API-ID} and {API-NAME} with the real values.

curl -X POST -H "authorization: {API-KEY}"
 -s
 -H "Content-Type: application/json"
 -X POST
 -d '{
    "allowance": 1000,
    "rate": 1000,
    "per": 1,
    "expires": -1,
    "quota_max": -1,
    "quota_renews": 1449051461,
    "quota_remaining": -1,
    "quota_renewal_rate": 60,
    "access_rights": {
        "{API-ID}": {
            "api_id": "{API-ID}",
            "api_name": "{API-NAME}",
            "versions": ["Default"]
        }
    },
    "meta_data": {}
 }'
 http://admin.cloud.tyk.io/api/keys | python -mjson.tool

You will see a response with your new token:

{
    "action": "create",
    "key": "c2cb92a78f944e9a46de793fe28e847e",
    "status": "ok"
}

The value returned in the key parameter of the response is the access token you can now use to access the API that was specified in the access_rights section of the call.

Was this article helpful to you? Yes No