curl --request POST \
--url https://{tenant}/api/apis \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"api_definition": {
"api_id": "b84fe1a04e5648927971c0557971565c",
"auth": {
"auth_header_name": "authorization"
},
"definition": {
"key": "version",
"location": "header"
},
"name": "Tyk Test API",
"org_id": "664a14650619d40001f1f00f",
"proxy": {
"listen_path": "/tyk-api-test-one/",
"strip_listen_path": true,
"target_url": "https://httpbin.org"
},
"use_oauth2": true,
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default"
}
}
}
}
}
'import requests
url = "https://{tenant}/api/apis"
payload = { "api_definition": {
"api_id": "b84fe1a04e5648927971c0557971565c",
"auth": { "auth_header_name": "authorization" },
"definition": {
"key": "version",
"location": "header"
},
"name": "Tyk Test API",
"org_id": "664a14650619d40001f1f00f",
"proxy": {
"listen_path": "/tyk-api-test-one/",
"strip_listen_path": True,
"target_url": "https://httpbin.org"
},
"use_oauth2": True,
"version_data": {
"not_versioned": True,
"versions": { "Default": { "name": "Default" } }
}
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
api_definition: {
api_id: 'b84fe1a04e5648927971c0557971565c',
auth: {auth_header_name: 'authorization'},
definition: {key: 'version', location: 'header'},
name: 'Tyk Test API',
org_id: '664a14650619d40001f1f00f',
proxy: {
listen_path: '/tyk-api-test-one/',
strip_listen_path: true,
target_url: 'https://httpbin.org'
},
use_oauth2: true,
version_data: {not_versioned: true, versions: {Default: {name: 'Default'}}}
}
})
};
fetch('https://{tenant}/api/apis', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{tenant}/api/apis",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'api_definition' => [
'api_id' => 'b84fe1a04e5648927971c0557971565c',
'auth' => [
'auth_header_name' => 'authorization'
],
'definition' => [
'key' => 'version',
'location' => 'header'
],
'name' => 'Tyk Test API',
'org_id' => '664a14650619d40001f1f00f',
'proxy' => [
'listen_path' => '/tyk-api-test-one/',
'strip_listen_path' => true,
'target_url' => 'https://httpbin.org'
],
'use_oauth2' => true,
'version_data' => [
'not_versioned' => true,
'versions' => [
'Default' => [
'name' => 'Default'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenant}/api/apis"
payload := strings.NewReader("{\n \"api_definition\": {\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"auth\": {\n \"auth_header_name\": \"authorization\"\n },\n \"definition\": {\n \"key\": \"version\",\n \"location\": \"header\"\n },\n \"name\": \"Tyk Test API\",\n \"org_id\": \"664a14650619d40001f1f00f\",\n \"proxy\": {\n \"listen_path\": \"/tyk-api-test-one/\",\n \"strip_listen_path\": true,\n \"target_url\": \"https://httpbin.org\"\n },\n \"use_oauth2\": true,\n \"version_data\": {\n \"not_versioned\": true,\n \"versions\": {\n \"Default\": {\n \"name\": \"Default\"\n }\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{tenant}/api/apis")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"api_definition\": {\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"auth\": {\n \"auth_header_name\": \"authorization\"\n },\n \"definition\": {\n \"key\": \"version\",\n \"location\": \"header\"\n },\n \"name\": \"Tyk Test API\",\n \"org_id\": \"664a14650619d40001f1f00f\",\n \"proxy\": {\n \"listen_path\": \"/tyk-api-test-one/\",\n \"strip_listen_path\": true,\n \"target_url\": \"https://httpbin.org\"\n },\n \"use_oauth2\": true,\n \"version_data\": {\n \"not_versioned\": true,\n \"versions\": {\n \"Default\": {\n \"name\": \"Default\"\n }\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_definition\": {\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"auth\": {\n \"auth_header_name\": \"authorization\"\n },\n \"definition\": {\n \"key\": \"version\",\n \"location\": \"header\"\n },\n \"name\": \"Tyk Test API\",\n \"org_id\": \"664a14650619d40001f1f00f\",\n \"proxy\": {\n \"listen_path\": \"/tyk-api-test-one/\",\n \"strip_listen_path\": true,\n \"target_url\": \"https://httpbin.org\"\n },\n \"use_oauth2\": true,\n \"version_data\": {\n \"not_versioned\": true,\n \"versions\": {\n \"Default\": {\n \"name\": \"Default\"\n }\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"ID": "284acad18f44f3d4e9a0832ccf5fd1",
"Message": "API created",
"Meta": "663cd8615715ec1405aafbea",
"Status": "OK"
}{
"Message": "version name header should be set with base API ID",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "access denied: You do not have permission to access /api/apis",
"Meta": null,
"Status": "Error"
}{
"Message": "Found API with the same ID",
"Meta": null,
"Status": "Error"
}Create API Definition
Create an API Definition in Tyk Classic API format.
Note that the response includes the newly created Tyk Classic API Definition containing the unique identifier for the APIs (api_id). You can provide a value for the api_id in the request body, otherwise Tyk will automatically generate a value for you.
The ID field within the Tyk Classic API Definition is a proprietary field used by Tyk to identify the API within the database and cannot be chosen or modified by the user.
curl --request POST \
--url https://{tenant}/api/apis \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"api_definition": {
"api_id": "b84fe1a04e5648927971c0557971565c",
"auth": {
"auth_header_name": "authorization"
},
"definition": {
"key": "version",
"location": "header"
},
"name": "Tyk Test API",
"org_id": "664a14650619d40001f1f00f",
"proxy": {
"listen_path": "/tyk-api-test-one/",
"strip_listen_path": true,
"target_url": "https://httpbin.org"
},
"use_oauth2": true,
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default"
}
}
}
}
}
'import requests
url = "https://{tenant}/api/apis"
payload = { "api_definition": {
"api_id": "b84fe1a04e5648927971c0557971565c",
"auth": { "auth_header_name": "authorization" },
"definition": {
"key": "version",
"location": "header"
},
"name": "Tyk Test API",
"org_id": "664a14650619d40001f1f00f",
"proxy": {
"listen_path": "/tyk-api-test-one/",
"strip_listen_path": True,
"target_url": "https://httpbin.org"
},
"use_oauth2": True,
"version_data": {
"not_versioned": True,
"versions": { "Default": { "name": "Default" } }
}
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
api_definition: {
api_id: 'b84fe1a04e5648927971c0557971565c',
auth: {auth_header_name: 'authorization'},
definition: {key: 'version', location: 'header'},
name: 'Tyk Test API',
org_id: '664a14650619d40001f1f00f',
proxy: {
listen_path: '/tyk-api-test-one/',
strip_listen_path: true,
target_url: 'https://httpbin.org'
},
use_oauth2: true,
version_data: {not_versioned: true, versions: {Default: {name: 'Default'}}}
}
})
};
fetch('https://{tenant}/api/apis', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{tenant}/api/apis",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'api_definition' => [
'api_id' => 'b84fe1a04e5648927971c0557971565c',
'auth' => [
'auth_header_name' => 'authorization'
],
'definition' => [
'key' => 'version',
'location' => 'header'
],
'name' => 'Tyk Test API',
'org_id' => '664a14650619d40001f1f00f',
'proxy' => [
'listen_path' => '/tyk-api-test-one/',
'strip_listen_path' => true,
'target_url' => 'https://httpbin.org'
],
'use_oauth2' => true,
'version_data' => [
'not_versioned' => true,
'versions' => [
'Default' => [
'name' => 'Default'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenant}/api/apis"
payload := strings.NewReader("{\n \"api_definition\": {\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"auth\": {\n \"auth_header_name\": \"authorization\"\n },\n \"definition\": {\n \"key\": \"version\",\n \"location\": \"header\"\n },\n \"name\": \"Tyk Test API\",\n \"org_id\": \"664a14650619d40001f1f00f\",\n \"proxy\": {\n \"listen_path\": \"/tyk-api-test-one/\",\n \"strip_listen_path\": true,\n \"target_url\": \"https://httpbin.org\"\n },\n \"use_oauth2\": true,\n \"version_data\": {\n \"not_versioned\": true,\n \"versions\": {\n \"Default\": {\n \"name\": \"Default\"\n }\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{tenant}/api/apis")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"api_definition\": {\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"auth\": {\n \"auth_header_name\": \"authorization\"\n },\n \"definition\": {\n \"key\": \"version\",\n \"location\": \"header\"\n },\n \"name\": \"Tyk Test API\",\n \"org_id\": \"664a14650619d40001f1f00f\",\n \"proxy\": {\n \"listen_path\": \"/tyk-api-test-one/\",\n \"strip_listen_path\": true,\n \"target_url\": \"https://httpbin.org\"\n },\n \"use_oauth2\": true,\n \"version_data\": {\n \"not_versioned\": true,\n \"versions\": {\n \"Default\": {\n \"name\": \"Default\"\n }\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_definition\": {\n \"api_id\": \"b84fe1a04e5648927971c0557971565c\",\n \"auth\": {\n \"auth_header_name\": \"authorization\"\n },\n \"definition\": {\n \"key\": \"version\",\n \"location\": \"header\"\n },\n \"name\": \"Tyk Test API\",\n \"org_id\": \"664a14650619d40001f1f00f\",\n \"proxy\": {\n \"listen_path\": \"/tyk-api-test-one/\",\n \"strip_listen_path\": true,\n \"target_url\": \"https://httpbin.org\"\n },\n \"use_oauth2\": true,\n \"version_data\": {\n \"not_versioned\": true,\n \"versions\": {\n \"Default\": {\n \"name\": \"Default\"\n }\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"ID": "284acad18f44f3d4e9a0832ccf5fd1",
"Message": "API created",
"Meta": "663cd8615715ec1405aafbea",
"Status": "OK"
}{
"Message": "version name header should be set with base API ID",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "access denied: You do not have permission to access /api/apis",
"Meta": null,
"Status": "Error"
}{
"Message": "Found API with the same ID",
"Meta": null,
"Status": "Error"
}Authorizations
The Tyk Dashboard API Access Credentials
Query Parameters
The base API which the new version will be linked to.
The version name of the base API while creating the first version. This doesn't have to be sent for the next versions but if it is set, it will override base API version name.
The version name of the created version.
If true, the new version is set as default version.
Body
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Was this page helpful?