Patch an API Definition with a merge patch
curl --request PATCH \
--url https://{tenant}/api/apis/{apiId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/merge-patch+json' \
--data '
{
"api_definition": {
"proxy": {
"target_url": "https://httpbin.org/anything"
}
}
}
'import requests
url = "https://{tenant}/api/apis/{apiId}"
payload = { "api_definition": { "proxy": { "target_url": "https://httpbin.org/anything" } } }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/merge-patch+json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {
Authorization: 'Bearer <token>',
'Content-Type': 'application/merge-patch+json'
},
body: JSON.stringify({api_definition: {proxy: {target_url: 'https://httpbin.org/anything'}}})
};
fetch('https://{tenant}/api/apis/{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/{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([
'api_definition' => [
'proxy' => [
'target_url' => 'https://httpbin.org/anything'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/merge-patch+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/{apiId}"
payload := strings.NewReader("{\n \"api_definition\": {\n \"proxy\": {\n \"target_url\": \"https://httpbin.org/anything\"\n }\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/merge-patch+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}/api/apis/{apiId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/merge-patch+json")
.body("{\n \"api_definition\": {\n \"proxy\": {\n \"target_url\": \"https://httpbin.org/anything\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/{apiId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/merge-patch+json'
request.body = "{\n \"api_definition\": {\n \"proxy\": {\n \"target_url\": \"https://httpbin.org/anything\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"Message": "Api updated",
"Meta": null,
"Status": "OK"
}{
"Message": "Merge patch must be a JSON object",
"Meta": null,
"Status": "Error"
}{
"ID": "<string>",
"Message": "<string>",
"Meta": "<unknown>",
"Status": "<string>"
}{
"Message": "api definition does not exist",
"Meta": null,
"Status": "Error"
}{
"Message": "The API definition kept changing during the update: retry",
"Meta": null,
"Status": "Error"
}{
"Message": "The API definition has changed since it was read: read it again and retry",
"Meta": null,
"Status": "Error"
}{
"Message": "Merge patch is too large",
"Meta": null,
"Status": "Error"
}{
"Message": "Unsupported Content-Type: use application/merge-patch+json",
"Meta": null,
"Status": "Error"
}APIs
Patch an API Definition with a merge patch
Apply an RFC 7396 JSON Merge Patch to the unresolved definition a GET returns.
null removes a key and arrays are replaced whole. The result is validated and
saved as a PUT would be. Send If-Match to make the update conditional; without
it, a patch that races another write is retried up to five times.
PATCH
/
api
/
apis
/
{apiId}
Patch an API Definition with a merge patch
curl --request PATCH \
--url https://{tenant}/api/apis/{apiId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/merge-patch+json' \
--data '
{
"api_definition": {
"proxy": {
"target_url": "https://httpbin.org/anything"
}
}
}
'import requests
url = "https://{tenant}/api/apis/{apiId}"
payload = { "api_definition": { "proxy": { "target_url": "https://httpbin.org/anything" } } }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/merge-patch+json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {
Authorization: 'Bearer <token>',
'Content-Type': 'application/merge-patch+json'
},
body: JSON.stringify({api_definition: {proxy: {target_url: 'https://httpbin.org/anything'}}})
};
fetch('https://{tenant}/api/apis/{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/{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([
'api_definition' => [
'proxy' => [
'target_url' => 'https://httpbin.org/anything'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/merge-patch+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/{apiId}"
payload := strings.NewReader("{\n \"api_definition\": {\n \"proxy\": {\n \"target_url\": \"https://httpbin.org/anything\"\n }\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/merge-patch+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}/api/apis/{apiId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/merge-patch+json")
.body("{\n \"api_definition\": {\n \"proxy\": {\n \"target_url\": \"https://httpbin.org/anything\"\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/{apiId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/merge-patch+json'
request.body = "{\n \"api_definition\": {\n \"proxy\": {\n \"target_url\": \"https://httpbin.org/anything\"\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"Message": "Api updated",
"Meta": null,
"Status": "OK"
}{
"Message": "Merge patch must be a JSON object",
"Meta": null,
"Status": "Error"
}{
"ID": "<string>",
"Message": "<string>",
"Meta": "<unknown>",
"Status": "<string>"
}{
"Message": "api definition does not exist",
"Meta": null,
"Status": "Error"
}{
"Message": "The API definition kept changing during the update: retry",
"Meta": null,
"Status": "Error"
}{
"Message": "The API definition has changed since it was read: read it again and retry",
"Meta": null,
"Status": "Error"
}{
"Message": "Merge patch is too large",
"Meta": null,
"Status": "Error"
}{
"Message": "Unsupported Content-Type: use application/merge-patch+json",
"Meta": null,
"Status": "Error"
}Authorizations
The Tyk Dashboard API Access Credentials
Headers
The ETag from a GET. If the definition has changed since, the PATCH returns 412. * matches any version.
Path Parameters
ID of the API. Can either be internal or public API ID.
Body
application/merge-patch+json
The body is of type object.
Was this page helpful?