Create an asset
curl --request POST \
--url https://{tenant}/api/assets \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"data": {
"info": {
"title": "Our Sample OAS",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/anything": {
"post": {
"operationId": "anythingpost",
"responses": {
"200": {
"description": "post created"
}
}
}
}
},
"x-tyk-api-gateway": {
"middleware": {
"global": {
"cache": {
"cacheAllSafeRequests": true,
"enabled": true,
"timeout": 5
}
}
}
}
},
"description": "My first template",
"id": "my-unique-template-id",
"kind": "oas-template",
"name": "my-template"
}
'import requests
url = "https://{tenant}/api/assets"
payload = {
"data": {
"info": {
"title": "Our Sample OAS",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": { "/anything": { "post": {
"operationId": "anythingpost",
"responses": { "200": { "description": "post created" } }
} } },
"x-tyk-api-gateway": { "middleware": { "global": { "cache": {
"cacheAllSafeRequests": True,
"enabled": True,
"timeout": 5
} } } }
},
"description": "My first template",
"id": "my-unique-template-id",
"kind": "oas-template",
"name": "my-template"
}
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({
data: {
info: {title: 'Our Sample OAS', version: '1.0.0'},
openapi: '3.0.3',
paths: {
'/anything': {
post: {operationId: 'anythingpost', responses: {'200': {description: 'post created'}}}
}
},
'x-tyk-api-gateway': {
middleware: {global: {cache: {cacheAllSafeRequests: true, enabled: true, timeout: 5}}}
}
},
description: 'My first template',
id: 'my-unique-template-id',
kind: 'oas-template',
name: 'my-template'
})
};
fetch('https://{tenant}/api/assets', 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/assets",
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([
'data' => [
'info' => [
'title' => 'Our Sample OAS',
'version' => '1.0.0'
],
'openapi' => '3.0.3',
'paths' => [
'/anything' => [
'post' => [
'operationId' => 'anythingpost',
'responses' => [
'200' => [
'description' => 'post created'
]
]
]
]
],
'x-tyk-api-gateway' => [
'middleware' => [
'global' => [
'cache' => [
'cacheAllSafeRequests' => true,
'enabled' => true,
'timeout' => 5
]
]
]
]
],
'description' => 'My first template',
'id' => 'my-unique-template-id',
'kind' => 'oas-template',
'name' => 'my-template'
]),
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/assets"
payload := strings.NewReader("{\n \"data\": {\n \"info\": {\n \"title\": \"Our Sample OAS\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/anything\": {\n \"post\": {\n \"operationId\": \"anythingpost\",\n \"responses\": {\n \"200\": {\n \"description\": \"post created\"\n }\n }\n }\n }\n },\n \"x-tyk-api-gateway\": {\n \"middleware\": {\n \"global\": {\n \"cache\": {\n \"cacheAllSafeRequests\": true,\n \"enabled\": true,\n \"timeout\": 5\n }\n }\n }\n }\n },\n \"description\": \"My first template\",\n \"id\": \"my-unique-template-id\",\n \"kind\": \"oas-template\",\n \"name\": \"my-template\"\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/assets")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"data\": {\n \"info\": {\n \"title\": \"Our Sample OAS\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/anything\": {\n \"post\": {\n \"operationId\": \"anythingpost\",\n \"responses\": {\n \"200\": {\n \"description\": \"post created\"\n }\n }\n }\n }\n },\n \"x-tyk-api-gateway\": {\n \"middleware\": {\n \"global\": {\n \"cache\": {\n \"cacheAllSafeRequests\": true,\n \"enabled\": true,\n \"timeout\": 5\n }\n }\n }\n }\n },\n \"description\": \"My first template\",\n \"id\": \"my-unique-template-id\",\n \"kind\": \"oas-template\",\n \"name\": \"my-template\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/assets")
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 \"data\": {\n \"info\": {\n \"title\": \"Our Sample OAS\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/anything\": {\n \"post\": {\n \"operationId\": \"anythingpost\",\n \"responses\": {\n \"200\": {\n \"description\": \"post created\"\n }\n }\n }\n }\n },\n \"x-tyk-api-gateway\": {\n \"middleware\": {\n \"global\": {\n \"cache\": {\n \"cacheAllSafeRequests\": true,\n \"enabled\": true,\n \"timeout\": 5\n }\n }\n }\n }\n },\n \"description\": \"My first template\",\n \"id\": \"my-unique-template-id\",\n \"kind\": \"oas-template\",\n \"name\": \"my-template\"\n}"
response = http.request(request)
puts response.read_body{
"ID": "my-unique-template-id",
"Message": "asset created",
"Meta": "664d86e35715ec0d370bbe11",
"Status": "success"
}{
"Message": "error reading json body.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "access denied: You do not have permission to access /api/assets",
"Meta": null,
"Status": "Error"
}{
"Message": "Asset ID already exists: 'my-unique-template-id'.",
"Meta": null,
"Status": "Error"
}{
"Message": "unsupported asset kind: 'oas-templat'.",
"Meta": null,
"Status": "Error"
}{
"Message": "error adding asset.",
"Meta": null,
"Status": "Error"
}Assets
Create an asset
Create an asset that you can use as a blueprint from which you can create a new Tyk OAS API definition.
POST
/
api
/
assets
Create an asset
curl --request POST \
--url https://{tenant}/api/assets \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"data": {
"info": {
"title": "Our Sample OAS",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/anything": {
"post": {
"operationId": "anythingpost",
"responses": {
"200": {
"description": "post created"
}
}
}
}
},
"x-tyk-api-gateway": {
"middleware": {
"global": {
"cache": {
"cacheAllSafeRequests": true,
"enabled": true,
"timeout": 5
}
}
}
}
},
"description": "My first template",
"id": "my-unique-template-id",
"kind": "oas-template",
"name": "my-template"
}
'import requests
url = "https://{tenant}/api/assets"
payload = {
"data": {
"info": {
"title": "Our Sample OAS",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": { "/anything": { "post": {
"operationId": "anythingpost",
"responses": { "200": { "description": "post created" } }
} } },
"x-tyk-api-gateway": { "middleware": { "global": { "cache": {
"cacheAllSafeRequests": True,
"enabled": True,
"timeout": 5
} } } }
},
"description": "My first template",
"id": "my-unique-template-id",
"kind": "oas-template",
"name": "my-template"
}
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({
data: {
info: {title: 'Our Sample OAS', version: '1.0.0'},
openapi: '3.0.3',
paths: {
'/anything': {
post: {operationId: 'anythingpost', responses: {'200': {description: 'post created'}}}
}
},
'x-tyk-api-gateway': {
middleware: {global: {cache: {cacheAllSafeRequests: true, enabled: true, timeout: 5}}}
}
},
description: 'My first template',
id: 'my-unique-template-id',
kind: 'oas-template',
name: 'my-template'
})
};
fetch('https://{tenant}/api/assets', 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/assets",
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([
'data' => [
'info' => [
'title' => 'Our Sample OAS',
'version' => '1.0.0'
],
'openapi' => '3.0.3',
'paths' => [
'/anything' => [
'post' => [
'operationId' => 'anythingpost',
'responses' => [
'200' => [
'description' => 'post created'
]
]
]
]
],
'x-tyk-api-gateway' => [
'middleware' => [
'global' => [
'cache' => [
'cacheAllSafeRequests' => true,
'enabled' => true,
'timeout' => 5
]
]
]
]
],
'description' => 'My first template',
'id' => 'my-unique-template-id',
'kind' => 'oas-template',
'name' => 'my-template'
]),
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/assets"
payload := strings.NewReader("{\n \"data\": {\n \"info\": {\n \"title\": \"Our Sample OAS\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/anything\": {\n \"post\": {\n \"operationId\": \"anythingpost\",\n \"responses\": {\n \"200\": {\n \"description\": \"post created\"\n }\n }\n }\n }\n },\n \"x-tyk-api-gateway\": {\n \"middleware\": {\n \"global\": {\n \"cache\": {\n \"cacheAllSafeRequests\": true,\n \"enabled\": true,\n \"timeout\": 5\n }\n }\n }\n }\n },\n \"description\": \"My first template\",\n \"id\": \"my-unique-template-id\",\n \"kind\": \"oas-template\",\n \"name\": \"my-template\"\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/assets")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"data\": {\n \"info\": {\n \"title\": \"Our Sample OAS\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/anything\": {\n \"post\": {\n \"operationId\": \"anythingpost\",\n \"responses\": {\n \"200\": {\n \"description\": \"post created\"\n }\n }\n }\n }\n },\n \"x-tyk-api-gateway\": {\n \"middleware\": {\n \"global\": {\n \"cache\": {\n \"cacheAllSafeRequests\": true,\n \"enabled\": true,\n \"timeout\": 5\n }\n }\n }\n }\n },\n \"description\": \"My first template\",\n \"id\": \"my-unique-template-id\",\n \"kind\": \"oas-template\",\n \"name\": \"my-template\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/assets")
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 \"data\": {\n \"info\": {\n \"title\": \"Our Sample OAS\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/anything\": {\n \"post\": {\n \"operationId\": \"anythingpost\",\n \"responses\": {\n \"200\": {\n \"description\": \"post created\"\n }\n }\n }\n }\n },\n \"x-tyk-api-gateway\": {\n \"middleware\": {\n \"global\": {\n \"cache\": {\n \"cacheAllSafeRequests\": true,\n \"enabled\": true,\n \"timeout\": 5\n }\n }\n }\n }\n },\n \"description\": \"My first template\",\n \"id\": \"my-unique-template-id\",\n \"kind\": \"oas-template\",\n \"name\": \"my-template\"\n}"
response = http.request(request)
puts response.read_body{
"ID": "my-unique-template-id",
"Message": "asset created",
"Meta": "664d86e35715ec0d370bbe11",
"Status": "success"
}{
"Message": "error reading json body.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "access denied: You do not have permission to access /api/assets",
"Meta": null,
"Status": "Error"
}{
"Message": "Asset ID already exists: 'my-unique-template-id'.",
"Meta": null,
"Status": "Error"
}{
"Message": "unsupported asset kind: 'oas-templat'.",
"Meta": null,
"Status": "Error"
}{
"Message": "error adding asset.",
"Meta": null,
"Status": "Error"
}Authorizations
The Tyk Dashboard API Access Credentials
Body
application/json
Sample asset.
Example:
{
"info": {
"title": "Our Sample OAS",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/anything": {
"post": {
"operationId": "anythingpost",
"responses": { "200": { "description": "Post created" } }
}
}
},
"x-tyk-api-gateway": {
"middleware": {
"global": {
"cache": {
"cacheAllSafeRequests": true,
"enabled": true,
"timeout": 5
}
},
"operations": {
"anythingpost": {
"requestSizeLimit": { "enabled": true, "value": 100 }
}
}
}
}
}
Was this page helpful?
⌘I