Update OAS API.
curl --request PUT \
--url https://{tenant}/api/apis/oas/{apiId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"components": {
"securitySchemes": {
"bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
}
}
},
"info": {
"description": "This is a sample OpenAPI description.",
"title": "Sample OpenAPI description",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/api/sample/users": {
"get": {
"operationId": "getUsersSample",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"items": {
"properties": {
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
}
},
"description": "fetched users"
}
},
"summary": "Get users",
"tags": [
"users"
]
}
}
},
"security": [
{
"bearerAuth": []
}
],
"servers": [
{
"url": "https://localhost:8080"
}
],
"x-tyk-api-gateway": {
"info": {
"name": "user",
"state": {
"active": true
}
},
"server": {
"listenPath": {
"strip": true,
"value": "/user-test-three/"
}
},
"upstream": {
"url": "https://localhost:8080"
}
}
}
'import requests
url = "https://{tenant}/api/apis/oas/{apiId}"
payload = {
"components": { "securitySchemes": { "bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
} } },
"info": {
"description": "This is a sample OpenAPI description.",
"title": "Sample OpenAPI description",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": { "/api/sample/users": { "get": {
"operationId": "getUsersSample",
"responses": { "200": {
"content": { "application/json": { "schema": {
"items": {
"properties": { "name": { "type": "string" } },
"type": "object"
},
"type": "array"
} } },
"description": "fetched users"
} },
"summary": "Get users",
"tags": ["users"]
} } },
"security": [{ "bearerAuth": [] }],
"servers": [{ "url": "https://localhost:8080" }],
"x-tyk-api-gateway": {
"info": {
"name": "user",
"state": { "active": True }
},
"server": { "listenPath": {
"strip": True,
"value": "/user-test-three/"
} },
"upstream": { "url": "https://localhost:8080" }
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
components: {
securitySchemes: {
bearerAuth: {description: 'The API Access Credentials', scheme: 'bearer', type: 'http'}
}
},
info: {
description: 'This is a sample OpenAPI description.',
title: 'Sample OpenAPI description',
version: '1.0.0'
},
openapi: '3.0.3',
paths: {
'/api/sample/users': {
get: {
operationId: 'getUsersSample',
responses: {
'200': {
content: {
'application/json': {
schema: {items: {properties: {name: {type: 'string'}}, type: 'object'}, type: 'array'}
}
},
description: 'fetched users'
}
},
summary: 'Get users',
tags: ['users']
}
}
},
security: [{bearerAuth: []}],
servers: [{url: 'https://localhost:8080'}],
'x-tyk-api-gateway': {
info: {name: 'user', state: {active: true}},
server: {listenPath: {strip: true, value: '/user-test-three/'}},
upstream: {url: 'https://localhost:8080'}
}
})
};
fetch('https://{tenant}/api/apis/oas/{apiId}', 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/oas/{apiId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'components' => [
'securitySchemes' => [
'bearerAuth' => [
'description' => 'The API Access Credentials',
'scheme' => 'bearer',
'type' => 'http'
]
]
],
'info' => [
'description' => 'This is a sample OpenAPI description.',
'title' => 'Sample OpenAPI description',
'version' => '1.0.0'
],
'openapi' => '3.0.3',
'paths' => [
'/api/sample/users' => [
'get' => [
'operationId' => 'getUsersSample',
'responses' => [
'200' => [
'content' => [
'application/json' => [
'schema' => [
'items' => [
'properties' => [
'name' => [
'type' => 'string'
]
],
'type' => 'object'
],
'type' => 'array'
]
]
],
'description' => 'fetched users'
]
],
'summary' => 'Get users',
'tags' => [
'users'
]
]
]
],
'security' => [
[
'bearerAuth' => [
]
]
],
'servers' => [
[
'url' => 'https://localhost:8080'
]
],
'x-tyk-api-gateway' => [
'info' => [
'name' => 'user',
'state' => [
'active' => true
]
],
'server' => [
'listenPath' => [
'strip' => true,
'value' => '/user-test-three/'
]
],
'upstream' => [
'url' => 'https://localhost:8080'
]
]
]),
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/oas/{apiId}"
payload := strings.NewReader("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample OpenAPI description.\",\n \"title\": \"Sample OpenAPI description\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-three/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
req, _ := http.NewRequest("PUT", 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.put("https://{tenant}/api/apis/oas/{apiId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample OpenAPI description.\",\n \"title\": \"Sample OpenAPI description\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-three/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/oas/{apiId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample OpenAPI description.\",\n \"title\": \"Sample OpenAPI description\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-three/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"Message": "API updated.",
"Meta": null,
"Status": "OK"
}{
"Message": "The payload should contain x-tyk-api-gateway.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Found API with same url.",
"Meta": null,
"Status": "Error"
}{
"Message": "API definition does not exist",
"Meta": null,
"Status": "Error"
}{
"Message": "Error while validating schema.",
"Meta": null,
"Status": "Error"
}OAS APIs
Update OAS API.
Updating an API definition uses the same signature object as a POST. It will first ensure that the API ID being updated is the same as in the PUT object.
Updating will completely replace the file descriptor and will not change an API definition that has already been loaded. The hot-reload endpoint will need to be called to push the new definition to live.
PUT
/
api
/
apis
/
oas
/
{apiId}
Update OAS API.
curl --request PUT \
--url https://{tenant}/api/apis/oas/{apiId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"components": {
"securitySchemes": {
"bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
}
}
},
"info": {
"description": "This is a sample OpenAPI description.",
"title": "Sample OpenAPI description",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/api/sample/users": {
"get": {
"operationId": "getUsersSample",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"items": {
"properties": {
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
}
},
"description": "fetched users"
}
},
"summary": "Get users",
"tags": [
"users"
]
}
}
},
"security": [
{
"bearerAuth": []
}
],
"servers": [
{
"url": "https://localhost:8080"
}
],
"x-tyk-api-gateway": {
"info": {
"name": "user",
"state": {
"active": true
}
},
"server": {
"listenPath": {
"strip": true,
"value": "/user-test-three/"
}
},
"upstream": {
"url": "https://localhost:8080"
}
}
}
'import requests
url = "https://{tenant}/api/apis/oas/{apiId}"
payload = {
"components": { "securitySchemes": { "bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
} } },
"info": {
"description": "This is a sample OpenAPI description.",
"title": "Sample OpenAPI description",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": { "/api/sample/users": { "get": {
"operationId": "getUsersSample",
"responses": { "200": {
"content": { "application/json": { "schema": {
"items": {
"properties": { "name": { "type": "string" } },
"type": "object"
},
"type": "array"
} } },
"description": "fetched users"
} },
"summary": "Get users",
"tags": ["users"]
} } },
"security": [{ "bearerAuth": [] }],
"servers": [{ "url": "https://localhost:8080" }],
"x-tyk-api-gateway": {
"info": {
"name": "user",
"state": { "active": True }
},
"server": { "listenPath": {
"strip": True,
"value": "/user-test-three/"
} },
"upstream": { "url": "https://localhost:8080" }
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
components: {
securitySchemes: {
bearerAuth: {description: 'The API Access Credentials', scheme: 'bearer', type: 'http'}
}
},
info: {
description: 'This is a sample OpenAPI description.',
title: 'Sample OpenAPI description',
version: '1.0.0'
},
openapi: '3.0.3',
paths: {
'/api/sample/users': {
get: {
operationId: 'getUsersSample',
responses: {
'200': {
content: {
'application/json': {
schema: {items: {properties: {name: {type: 'string'}}, type: 'object'}, type: 'array'}
}
},
description: 'fetched users'
}
},
summary: 'Get users',
tags: ['users']
}
}
},
security: [{bearerAuth: []}],
servers: [{url: 'https://localhost:8080'}],
'x-tyk-api-gateway': {
info: {name: 'user', state: {active: true}},
server: {listenPath: {strip: true, value: '/user-test-three/'}},
upstream: {url: 'https://localhost:8080'}
}
})
};
fetch('https://{tenant}/api/apis/oas/{apiId}', 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/oas/{apiId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'components' => [
'securitySchemes' => [
'bearerAuth' => [
'description' => 'The API Access Credentials',
'scheme' => 'bearer',
'type' => 'http'
]
]
],
'info' => [
'description' => 'This is a sample OpenAPI description.',
'title' => 'Sample OpenAPI description',
'version' => '1.0.0'
],
'openapi' => '3.0.3',
'paths' => [
'/api/sample/users' => [
'get' => [
'operationId' => 'getUsersSample',
'responses' => [
'200' => [
'content' => [
'application/json' => [
'schema' => [
'items' => [
'properties' => [
'name' => [
'type' => 'string'
]
],
'type' => 'object'
],
'type' => 'array'
]
]
],
'description' => 'fetched users'
]
],
'summary' => 'Get users',
'tags' => [
'users'
]
]
]
],
'security' => [
[
'bearerAuth' => [
]
]
],
'servers' => [
[
'url' => 'https://localhost:8080'
]
],
'x-tyk-api-gateway' => [
'info' => [
'name' => 'user',
'state' => [
'active' => true
]
],
'server' => [
'listenPath' => [
'strip' => true,
'value' => '/user-test-three/'
]
],
'upstream' => [
'url' => 'https://localhost:8080'
]
]
]),
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/oas/{apiId}"
payload := strings.NewReader("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample OpenAPI description.\",\n \"title\": \"Sample OpenAPI description\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-three/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
req, _ := http.NewRequest("PUT", 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.put("https://{tenant}/api/apis/oas/{apiId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample OpenAPI description.\",\n \"title\": \"Sample OpenAPI description\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-three/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/oas/{apiId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample OpenAPI description.\",\n \"title\": \"Sample OpenAPI description\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-three/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"Message": "API updated.",
"Meta": null,
"Status": "OK"
}{
"Message": "The payload should contain x-tyk-api-gateway.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Found API with same url.",
"Meta": null,
"Status": "Error"
}{
"Message": "API definition does not exist",
"Meta": null,
"Status": "Error"
}{
"Message": "Error while validating schema.",
"Meta": null,
"Status": "Error"
}Authorizations
The Tyk Dashboard API Access Credentials
Path Parameters
ID of the API you want to update.
Body
application/jsonapplication/x-yaml
Show child attributes
Show child attributes
Was this page helpful?
⌘I