Set policies for a hashed key.
curl --request POST \
--url https://{tenant}/tyk/keys/policy/{keyID} \
--header 'Content-Type: application/json' \
--header 'X-Tyk-Authorization: <api-key>' \
--data '
{
"apply_policies": [
"5ead7120575961000181867e"
],
"policy": ""
}
'import requests
url = "https://{tenant}/tyk/keys/policy/{keyID}"
payload = {
"apply_policies": ["5ead7120575961000181867e"],
"policy": ""
}
headers = {
"X-Tyk-Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Tyk-Authorization': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({apply_policies: ['5ead7120575961000181867e'], policy: ''})
};
fetch('https://{tenant}/tyk/keys/policy/{keyID}', 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/keys/policy/{keyID}",
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([
'apply_policies' => [
'5ead7120575961000181867e'
],
'policy' => ''
]),
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/keys/policy/{keyID}"
payload := strings.NewReader("{\n \"apply_policies\": [\n \"5ead7120575961000181867e\"\n ],\n \"policy\": \"\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://{tenant}/tyk/keys/policy/{keyID}")
.header("X-Tyk-Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"apply_policies\": [\n \"5ead7120575961000181867e\"\n ],\n \"policy\": \"\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/tyk/keys/policy/{keyID}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Tyk-Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"apply_policies\": [\n \"5ead7120575961000181867e\"\n ],\n \"policy\": \"\"\n}"
response = http.request(request)
puts response.read_body{
"action": "updated",
"key": "5e9d9544a1dcd60001d0ed207eb558517c3c48fb826c62cc6f6161eb",
"status": "ok"
}{
"message": "Couldn't decode instruction",
"status": "error"
}{
"message": "Attempted administrative access with invalid or missing key!",
"status": "error"
}{
"message": "Key not found",
"status": "error"
}{
"message": "Could not write key data.",
"status": "error"
}Keys
Set policies for a hashed key.
This will set policies to a hashed key.
POST
/
tyk
/
keys
/
policy
/
{keyID}
Set policies for a hashed key.
curl --request POST \
--url https://{tenant}/tyk/keys/policy/{keyID} \
--header 'Content-Type: application/json' \
--header 'X-Tyk-Authorization: <api-key>' \
--data '
{
"apply_policies": [
"5ead7120575961000181867e"
],
"policy": ""
}
'import requests
url = "https://{tenant}/tyk/keys/policy/{keyID}"
payload = {
"apply_policies": ["5ead7120575961000181867e"],
"policy": ""
}
headers = {
"X-Tyk-Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Tyk-Authorization': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({apply_policies: ['5ead7120575961000181867e'], policy: ''})
};
fetch('https://{tenant}/tyk/keys/policy/{keyID}', 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/keys/policy/{keyID}",
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([
'apply_policies' => [
'5ead7120575961000181867e'
],
'policy' => ''
]),
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/keys/policy/{keyID}"
payload := strings.NewReader("{\n \"apply_policies\": [\n \"5ead7120575961000181867e\"\n ],\n \"policy\": \"\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://{tenant}/tyk/keys/policy/{keyID}")
.header("X-Tyk-Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"apply_policies\": [\n \"5ead7120575961000181867e\"\n ],\n \"policy\": \"\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/tyk/keys/policy/{keyID}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Tyk-Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"apply_policies\": [\n \"5ead7120575961000181867e\"\n ],\n \"policy\": \"\"\n}"
response = http.request(request)
puts response.read_body{
"action": "updated",
"key": "5e9d9544a1dcd60001d0ed207eb558517c3c48fb826c62cc6f6161eb",
"status": "ok"
}{
"message": "Couldn't decode instruction",
"status": "error"
}{
"message": "Attempted administrative access with invalid or missing key!",
"status": "error"
}{
"message": "Key not found",
"status": "error"
}{
"message": "Could not write key data.",
"status": "error"
}Authorizations
Api key
Path Parameters
Name to give the custom key.
Was this page helpful?
⌘I