Tyk v2.2 Documentation Components

  1. Home
  2. Tyk v2.2 Documentation Components
  3. Tutorial: Create API Without GUI (Cloud)

Tutorial: Create API Without GUI (Cloud)

With Tyk Cloud, it is also possible to programatically create APIs using Tyk’s REST API, in order to do so you will need an API key for your organisation and one command to create the API and make it live.

Step 1: Get an API key for Tyk Cloud

To get your API key, go to the Users management page, click edit on your user account, then scroll to the bottom of the page. Your API Key is the first entry:

API key location

Step 2: Create an API

To create the API, let’s send a definition to the admin endpoint:

curl -H "Authorization: 1238b7e0e2ff4c2957321724409ee2eb" 
 -s 
 -H "Content-Type: application/json" 
 -X POST 
 -d '{
    "api_definition": {
        "name": "Test API",
        "slug": "test-api",
        "auth": {
            "auth_header_name": "Authorization"
        },
        "definition": {
            "location": "header",
            "key": "x-api-version"
        },
        "version_data": {
            "not_versioned": true,
            "versions": {
                "Default": {
                    "name": "Default",
                    "use_extended_paths": true
                }
            }
        },
        "proxy": {
            "listen_path": "/test-api/",
            "target_url": "http://httpbin.org/",
            "strip_listen_path": true
        },
        "active": true
    }
 }' https://admin.cloud.tyk.io/api/apis/ | python -mjson.tool

If the command succeeds, you will see:

{
    "action": "added",
    "key": "1",
    "status": "ok"
}

What did we just do?

We just sent an API Definition to the Tyk /apis endpoint, API Definitions are discussed in detail in the API section of this documentation. These objects encapsulate all of the settings for an API within Tyk Cloud.