Patch API in Tyk OAS format.
curl --request PATCH \
--url https://{tenant}/tyk/apis/oas/{apiID} \
--header 'Content-Type: application/json' \
--header 'X-Tyk-Authorization: <api-key>' \
--data '
{
"components": {
"securitySchemes": {
"bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
}
}
},
"info": {
"description": "This is a sample OAS.",
"title": "OAS Sample",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/api/sample/users": {
"get": {
"operationId": "getUsers",
"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/"
}
},
"upstream": {
"url": "https://localhost:8080"
}
}
}
'import requests
url = "https://{tenant}/tyk/apis/oas/{apiID}"
payload = {
"components": { "securitySchemes": { "bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
} } },
"info": {
"description": "This is a sample OAS.",
"title": "OAS Sample",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": { "/api/sample/users": { "get": {
"operationId": "getUsers",
"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/"
} },
"upstream": { "url": "https://localhost:8080" }
}
}
headers = {
"X-Tyk-Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-Tyk-Authorization': '<api-key>', '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 OAS.', title: 'OAS Sample', version: '1.0.0'},
openapi: '3.0.3',
paths: {
'/api/sample/users': {
get: {
operationId: 'getUsers',
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/'}},
upstream: {url: 'https://localhost:8080'}
}
})
};
fetch('https://{tenant}/tyk/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}/tyk/apis/oas/{apiID}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'components' => [
'securitySchemes' => [
'bearerAuth' => [
'description' => 'The API Access Credentials',
'scheme' => 'bearer',
'type' => 'http'
]
]
],
'info' => [
'description' => 'This is a sample OAS.',
'title' => 'OAS Sample',
'version' => '1.0.0'
],
'openapi' => '3.0.3',
'paths' => [
'/api/sample/users' => [
'get' => [
'operationId' => 'getUsers',
'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/'
]
],
'upstream' => [
'url' => 'https://localhost:8080'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Tyk-Authorization: <api-key>"
],
]);
$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}/tyk/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 OAS.\",\n \"title\": \"OAS Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsers\",\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/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-Tyk-Authorization", "<api-key>")
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.patch("https://{tenant}/tyk/apis/oas/{apiID}")
.header("X-Tyk-Authorization", "<api-key>")
.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 OAS.\",\n \"title\": \"OAS Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsers\",\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/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/tyk/apis/oas/{apiID}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-Tyk-Authorization"] = '<api-key>'
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 OAS.\",\n \"title\": \"OAS Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsers\",\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/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"action": "modified",
"key": "b13d928b9972bd18",
"key_hash": "<string>",
"status": "ok"
}{
"message": "Must specify an apiID to patch",
"status": "error"
}{
"message": "Attempted administrative access with invalid or missing key!",
"status": "error"
}{
"message": "API not found",
"status": "error"
}{
"message": "file object creation failed, write error",
"status": "error"
}Tyk OAS APIs
Patch API in Tyk OAS format.
You can use this endpoint to update Tyk OAS part of the Tyk API definition. This endpoint allows you to configure Tyk OAS extension based on query params provided(similar to import).
PATCH
/
tyk
/
apis
/
oas
/
{apiID}
Patch API in Tyk OAS format.
curl --request PATCH \
--url https://{tenant}/tyk/apis/oas/{apiID} \
--header 'Content-Type: application/json' \
--header 'X-Tyk-Authorization: <api-key>' \
--data '
{
"components": {
"securitySchemes": {
"bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
}
}
},
"info": {
"description": "This is a sample OAS.",
"title": "OAS Sample",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/api/sample/users": {
"get": {
"operationId": "getUsers",
"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/"
}
},
"upstream": {
"url": "https://localhost:8080"
}
}
}
'import requests
url = "https://{tenant}/tyk/apis/oas/{apiID}"
payload = {
"components": { "securitySchemes": { "bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
} } },
"info": {
"description": "This is a sample OAS.",
"title": "OAS Sample",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": { "/api/sample/users": { "get": {
"operationId": "getUsers",
"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/"
} },
"upstream": { "url": "https://localhost:8080" }
}
}
headers = {
"X-Tyk-Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-Tyk-Authorization': '<api-key>', '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 OAS.', title: 'OAS Sample', version: '1.0.0'},
openapi: '3.0.3',
paths: {
'/api/sample/users': {
get: {
operationId: 'getUsers',
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/'}},
upstream: {url: 'https://localhost:8080'}
}
})
};
fetch('https://{tenant}/tyk/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}/tyk/apis/oas/{apiID}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'components' => [
'securitySchemes' => [
'bearerAuth' => [
'description' => 'The API Access Credentials',
'scheme' => 'bearer',
'type' => 'http'
]
]
],
'info' => [
'description' => 'This is a sample OAS.',
'title' => 'OAS Sample',
'version' => '1.0.0'
],
'openapi' => '3.0.3',
'paths' => [
'/api/sample/users' => [
'get' => [
'operationId' => 'getUsers',
'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/'
]
],
'upstream' => [
'url' => 'https://localhost:8080'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Tyk-Authorization: <api-key>"
],
]);
$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}/tyk/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 OAS.\",\n \"title\": \"OAS Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsers\",\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/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-Tyk-Authorization", "<api-key>")
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.patch("https://{tenant}/tyk/apis/oas/{apiID}")
.header("X-Tyk-Authorization", "<api-key>")
.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 OAS.\",\n \"title\": \"OAS Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsers\",\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/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/tyk/apis/oas/{apiID}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-Tyk-Authorization"] = '<api-key>'
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 OAS.\",\n \"title\": \"OAS Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsers\",\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/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"action": "modified",
"key": "b13d928b9972bd18",
"key_hash": "<string>",
"status": "ok"
}{
"message": "Must specify an apiID to patch",
"status": "error"
}{
"message": "Attempted administrative access with invalid or missing key!",
"status": "error"
}{
"message": "API not found",
"status": "error"
}{
"message": "file object creation failed, write error",
"status": "error"
}Authorizations
Api key
Path Parameters
ID of the API you want to fetch.
Query Parameters
Upstream URL for the API
Listen path for the API
Custom domain for the API
Enable allowList middleware for all endpoints
Available options:
true, false Example:
true
Enable validateRequest middleware for all endpoints having a request body with media type application/json
Available options:
true, false Example:
true
Enable mockResponse middleware for all endpoints having responses configured.
Available options:
true, false Example:
true
Enable/disable the authentication mechanism in your Tyk Gateway for your OAS API
Available options:
true, false Example:
true
Body
application/json
The body is of type object.
Was this page helpful?
⌘I