curl --request POST \
--url https://{tenant}/api/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"alias": "portal-key",
"allowance": 1000,
"apply_policies": [
"62a0ec9092faf50001395817"
],
"enable_detailed_recording": true,
"expires": 1718439136,
"hmac_enabled": false,
"is_inactive": false,
"meta_data": {
"tyk_developer_id": "62b3fb9a1d5e4f00017226f5"
},
"org_id": "5e9d9544a1dcd60001d0ed20",
"per": 60,
"quota_max": -1,
"quota_remaining": 0,
"quota_renewal_rate": -1,
"quota_renews": 1715847135,
"rate": 1000,
"tags": [
"edge-eu",
"edge"
],
"throttle_interval": 0,
"throttle_retry_limit": 0
}
'import requests
url = "https://{tenant}/api/keys"
payload = {
"alias": "portal-key",
"allowance": 1000,
"apply_policies": ["62a0ec9092faf50001395817"],
"enable_detailed_recording": True,
"expires": 1718439136,
"hmac_enabled": False,
"is_inactive": False,
"meta_data": { "tyk_developer_id": "62b3fb9a1d5e4f00017226f5" },
"org_id": "5e9d9544a1dcd60001d0ed20",
"per": 60,
"quota_max": -1,
"quota_remaining": 0,
"quota_renewal_rate": -1,
"quota_renews": 1715847135,
"rate": 1000,
"tags": ["edge-eu", "edge"],
"throttle_interval": 0,
"throttle_retry_limit": 0
}
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({
alias: 'portal-key',
allowance: 1000,
apply_policies: ['62a0ec9092faf50001395817'],
enable_detailed_recording: true,
expires: 1718439136,
hmac_enabled: false,
is_inactive: false,
meta_data: {tyk_developer_id: '62b3fb9a1d5e4f00017226f5'},
org_id: '5e9d9544a1dcd60001d0ed20',
per: 60,
quota_max: -1,
quota_remaining: 0,
quota_renewal_rate: -1,
quota_renews: 1715847135,
rate: 1000,
tags: ['edge-eu', 'edge'],
throttle_interval: 0,
throttle_retry_limit: 0
})
};
fetch('https://{tenant}/api/keys', 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/keys",
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([
'alias' => 'portal-key',
'allowance' => 1000,
'apply_policies' => [
'62a0ec9092faf50001395817'
],
'enable_detailed_recording' => true,
'expires' => 1718439136,
'hmac_enabled' => false,
'is_inactive' => false,
'meta_data' => [
'tyk_developer_id' => '62b3fb9a1d5e4f00017226f5'
],
'org_id' => '5e9d9544a1dcd60001d0ed20',
'per' => 60,
'quota_max' => -1,
'quota_remaining' => 0,
'quota_renewal_rate' => -1,
'quota_renews' => 1715847135,
'rate' => 1000,
'tags' => [
'edge-eu',
'edge'
],
'throttle_interval' => 0,
'throttle_retry_limit' => 0
]),
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/keys"
payload := strings.NewReader("{\n \"alias\": \"portal-key\",\n \"allowance\": 1000,\n \"apply_policies\": [\n \"62a0ec9092faf50001395817\"\n ],\n \"enable_detailed_recording\": true,\n \"expires\": 1718439136,\n \"hmac_enabled\": false,\n \"is_inactive\": false,\n \"meta_data\": {\n \"tyk_developer_id\": \"62b3fb9a1d5e4f00017226f5\"\n },\n \"org_id\": \"5e9d9544a1dcd60001d0ed20\",\n \"per\": 60,\n \"quota_max\": -1,\n \"quota_remaining\": 0,\n \"quota_renewal_rate\": -1,\n \"quota_renews\": 1715847135,\n \"rate\": 1000,\n \"tags\": [\n \"edge-eu\",\n \"edge\"\n ],\n \"throttle_interval\": 0,\n \"throttle_retry_limit\": 0\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/keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"alias\": \"portal-key\",\n \"allowance\": 1000,\n \"apply_policies\": [\n \"62a0ec9092faf50001395817\"\n ],\n \"enable_detailed_recording\": true,\n \"expires\": 1718439136,\n \"hmac_enabled\": false,\n \"is_inactive\": false,\n \"meta_data\": {\n \"tyk_developer_id\": \"62b3fb9a1d5e4f00017226f5\"\n },\n \"org_id\": \"5e9d9544a1dcd60001d0ed20\",\n \"per\": 60,\n \"quota_max\": -1,\n \"quota_remaining\": 0,\n \"quota_renewal_rate\": -1,\n \"quota_renews\": 1715847135,\n \"rate\": 1000,\n \"tags\": [\n \"edge-eu\",\n \"edge\"\n ],\n \"throttle_interval\": 0,\n \"throttle_retry_limit\": 0\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/keys")
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 \"alias\": \"portal-key\",\n \"allowance\": 1000,\n \"apply_policies\": [\n \"62a0ec9092faf50001395817\"\n ],\n \"enable_detailed_recording\": true,\n \"expires\": 1718439136,\n \"hmac_enabled\": false,\n \"is_inactive\": false,\n \"meta_data\": {\n \"tyk_developer_id\": \"62b3fb9a1d5e4f00017226f5\"\n },\n \"org_id\": \"5e9d9544a1dcd60001d0ed20\",\n \"per\": 60,\n \"quota_max\": -1,\n \"quota_remaining\": 0,\n \"quota_renewal_rate\": -1,\n \"quota_renews\": 1715847135,\n \"rate\": 1000,\n \"tags\": [\n \"edge-eu\",\n \"edge\"\n ],\n \"throttle_interval\": 0,\n \"throttle_retry_limit\": 0\n}"
response = http.request(request)
puts response.read_body{
"api_model": {},
"data": {
"access_rights": {},
"alias": "portal-developer@example.org",
"allowance": 1000,
"apply_policies": [
"641c15dd0fffb800010197bf",
"615d2e528bf3980001c7c6c2"
],
"apply_policy_id": "641c15dd0fffb800010197bf",
"basic_auth_data": {
"hash_type": "bcrypt",
"password": "testuse1",
"user": "admin-user@example.org"
},
"certificate": "<string>",
"mtls_static_certificate_bindings": [
"<string>"
],
"data_expires": 0,
"date_created": "2024-05-14T13:15:46.560506+03:00",
"enable_detailed_recording": true,
"expires": 1716895221,
"hmac_enabled": false,
"hmac_string": "<string>",
"id_extractor_deadline": 0,
"is_inactive": true,
"jwt_data": {
"secret": "<string>"
},
"key_id": "<string>",
"last_check": 0,
"last_updated": "1715681746",
"max_query_depth": 5,
"meta_data": "<unknown>",
"monitor": {
"trigger_limits": [
80,
60,
50
]
},
"oauth_client_id": "<string>",
"oauth_keys": {},
"org_id": "5e9d9544a1dcd60001d0ed20",
"per": 60,
"post_expiry_action": "delete",
"post_expiry_grace_period": 0,
"quota_max": 1710302205,
"quota_remaining": 20000,
"quota_renewal_rate": -1,
"quota_renews": 1715681745,
"rate": 1000,
"session_lifetime": 0,
"smoothing": {
"delay": 2,
"enabled": true,
"step": 2,
"threshold": 2,
"trigger": 1
},
"tags": [
"edge",
"edge-eu"
],
"throttle_interval": 10,
"throttle_retry_limit": -1
},
"key_hash": "41c5cb1e",
"key_id": "5e9d9544a1dcd60001d0ed20e7f75f9e03534825b7aef9df749582e5"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Request body malformed.",
"Meta": null,
"Status": "Error"
}{
"Message": "Failed to unmarshal key data.",
"Meta": null,
"Status": "Error"
}Create a key.
Tyk will generate the access token based on the OrgID specified in the API Definition and a random UUID. This ensures that keys can be owned by different API owners should segmentation be needed at an organisational level.
API keys without access_rights data will be written to all APIs on the system (this also means that they will be created across all SessionHandlers and StorageHandlers, it is recommended to always embed access_rights data in a key to ensure that only targeted APIs and their back-ends are written to.
curl --request POST \
--url https://{tenant}/api/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"alias": "portal-key",
"allowance": 1000,
"apply_policies": [
"62a0ec9092faf50001395817"
],
"enable_detailed_recording": true,
"expires": 1718439136,
"hmac_enabled": false,
"is_inactive": false,
"meta_data": {
"tyk_developer_id": "62b3fb9a1d5e4f00017226f5"
},
"org_id": "5e9d9544a1dcd60001d0ed20",
"per": 60,
"quota_max": -1,
"quota_remaining": 0,
"quota_renewal_rate": -1,
"quota_renews": 1715847135,
"rate": 1000,
"tags": [
"edge-eu",
"edge"
],
"throttle_interval": 0,
"throttle_retry_limit": 0
}
'import requests
url = "https://{tenant}/api/keys"
payload = {
"alias": "portal-key",
"allowance": 1000,
"apply_policies": ["62a0ec9092faf50001395817"],
"enable_detailed_recording": True,
"expires": 1718439136,
"hmac_enabled": False,
"is_inactive": False,
"meta_data": { "tyk_developer_id": "62b3fb9a1d5e4f00017226f5" },
"org_id": "5e9d9544a1dcd60001d0ed20",
"per": 60,
"quota_max": -1,
"quota_remaining": 0,
"quota_renewal_rate": -1,
"quota_renews": 1715847135,
"rate": 1000,
"tags": ["edge-eu", "edge"],
"throttle_interval": 0,
"throttle_retry_limit": 0
}
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({
alias: 'portal-key',
allowance: 1000,
apply_policies: ['62a0ec9092faf50001395817'],
enable_detailed_recording: true,
expires: 1718439136,
hmac_enabled: false,
is_inactive: false,
meta_data: {tyk_developer_id: '62b3fb9a1d5e4f00017226f5'},
org_id: '5e9d9544a1dcd60001d0ed20',
per: 60,
quota_max: -1,
quota_remaining: 0,
quota_renewal_rate: -1,
quota_renews: 1715847135,
rate: 1000,
tags: ['edge-eu', 'edge'],
throttle_interval: 0,
throttle_retry_limit: 0
})
};
fetch('https://{tenant}/api/keys', 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/keys",
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([
'alias' => 'portal-key',
'allowance' => 1000,
'apply_policies' => [
'62a0ec9092faf50001395817'
],
'enable_detailed_recording' => true,
'expires' => 1718439136,
'hmac_enabled' => false,
'is_inactive' => false,
'meta_data' => [
'tyk_developer_id' => '62b3fb9a1d5e4f00017226f5'
],
'org_id' => '5e9d9544a1dcd60001d0ed20',
'per' => 60,
'quota_max' => -1,
'quota_remaining' => 0,
'quota_renewal_rate' => -1,
'quota_renews' => 1715847135,
'rate' => 1000,
'tags' => [
'edge-eu',
'edge'
],
'throttle_interval' => 0,
'throttle_retry_limit' => 0
]),
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/keys"
payload := strings.NewReader("{\n \"alias\": \"portal-key\",\n \"allowance\": 1000,\n \"apply_policies\": [\n \"62a0ec9092faf50001395817\"\n ],\n \"enable_detailed_recording\": true,\n \"expires\": 1718439136,\n \"hmac_enabled\": false,\n \"is_inactive\": false,\n \"meta_data\": {\n \"tyk_developer_id\": \"62b3fb9a1d5e4f00017226f5\"\n },\n \"org_id\": \"5e9d9544a1dcd60001d0ed20\",\n \"per\": 60,\n \"quota_max\": -1,\n \"quota_remaining\": 0,\n \"quota_renewal_rate\": -1,\n \"quota_renews\": 1715847135,\n \"rate\": 1000,\n \"tags\": [\n \"edge-eu\",\n \"edge\"\n ],\n \"throttle_interval\": 0,\n \"throttle_retry_limit\": 0\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/keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"alias\": \"portal-key\",\n \"allowance\": 1000,\n \"apply_policies\": [\n \"62a0ec9092faf50001395817\"\n ],\n \"enable_detailed_recording\": true,\n \"expires\": 1718439136,\n \"hmac_enabled\": false,\n \"is_inactive\": false,\n \"meta_data\": {\n \"tyk_developer_id\": \"62b3fb9a1d5e4f00017226f5\"\n },\n \"org_id\": \"5e9d9544a1dcd60001d0ed20\",\n \"per\": 60,\n \"quota_max\": -1,\n \"quota_remaining\": 0,\n \"quota_renewal_rate\": -1,\n \"quota_renews\": 1715847135,\n \"rate\": 1000,\n \"tags\": [\n \"edge-eu\",\n \"edge\"\n ],\n \"throttle_interval\": 0,\n \"throttle_retry_limit\": 0\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/keys")
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 \"alias\": \"portal-key\",\n \"allowance\": 1000,\n \"apply_policies\": [\n \"62a0ec9092faf50001395817\"\n ],\n \"enable_detailed_recording\": true,\n \"expires\": 1718439136,\n \"hmac_enabled\": false,\n \"is_inactive\": false,\n \"meta_data\": {\n \"tyk_developer_id\": \"62b3fb9a1d5e4f00017226f5\"\n },\n \"org_id\": \"5e9d9544a1dcd60001d0ed20\",\n \"per\": 60,\n \"quota_max\": -1,\n \"quota_remaining\": 0,\n \"quota_renewal_rate\": -1,\n \"quota_renews\": 1715847135,\n \"rate\": 1000,\n \"tags\": [\n \"edge-eu\",\n \"edge\"\n ],\n \"throttle_interval\": 0,\n \"throttle_retry_limit\": 0\n}"
response = http.request(request)
puts response.read_body{
"api_model": {},
"data": {
"access_rights": {},
"alias": "portal-developer@example.org",
"allowance": 1000,
"apply_policies": [
"641c15dd0fffb800010197bf",
"615d2e528bf3980001c7c6c2"
],
"apply_policy_id": "641c15dd0fffb800010197bf",
"basic_auth_data": {
"hash_type": "bcrypt",
"password": "testuse1",
"user": "admin-user@example.org"
},
"certificate": "<string>",
"mtls_static_certificate_bindings": [
"<string>"
],
"data_expires": 0,
"date_created": "2024-05-14T13:15:46.560506+03:00",
"enable_detailed_recording": true,
"expires": 1716895221,
"hmac_enabled": false,
"hmac_string": "<string>",
"id_extractor_deadline": 0,
"is_inactive": true,
"jwt_data": {
"secret": "<string>"
},
"key_id": "<string>",
"last_check": 0,
"last_updated": "1715681746",
"max_query_depth": 5,
"meta_data": "<unknown>",
"monitor": {
"trigger_limits": [
80,
60,
50
]
},
"oauth_client_id": "<string>",
"oauth_keys": {},
"org_id": "5e9d9544a1dcd60001d0ed20",
"per": 60,
"post_expiry_action": "delete",
"post_expiry_grace_period": 0,
"quota_max": 1710302205,
"quota_remaining": 20000,
"quota_renewal_rate": -1,
"quota_renews": 1715681745,
"rate": 1000,
"session_lifetime": 0,
"smoothing": {
"delay": 2,
"enabled": true,
"step": 2,
"threshold": 2,
"trigger": 1
},
"tags": [
"edge",
"edge-eu"
],
"throttle_interval": 10,
"throttle_retry_limit": -1
},
"key_hash": "41c5cb1e",
"key_id": "5e9d9544a1dcd60001d0ed20e7f75f9e03534825b7aef9df749582e5"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Request body malformed.",
"Meta": null,
"Status": "Error"
}{
"Message": "Failed to unmarshal key data.",
"Meta": null,
"Status": "Error"
}Authorizations
The Tyk Dashboard API Access Credentials
Query Parameters
Set this to true to create a basic user. Note you have to send basic_auth_data(user and password) in the request body if this value is set to true.
Body
Show child attributes
Show child attributes
"portal-developer@example.org"
1000
[
"641c15dd0fffb800010197bf",
"615d2e528bf3980001c7c6c2"
]
deprecated use apply_policies going forward instead to send a list of policies ids
"641c15dd0fffb800010197bf"
Show child attributes
Show child attributes
0
"2024-05-14T13:15:46.560506+03:00"
true
1716895221
false
0
Show child attributes
Show child attributes
0
"1715681746"
5
Show child attributes
Show child attributes
Show child attributes
Show child attributes
"5e9d9544a1dcd60001d0ed20"
60
Defines the action to take on a Session in Redis after it expires. Valid values are "retain" and "delete", leave empty for legacy session lifetime controls.
retain, delete "delete"
Duration in seconds to retain a Session in Redis after it expires. Used with post_expiry_action "retain". Set to -1 to retain indefinitely. Set to 0 to use legacy session lifetime controls.
0
1710302205
20000
-1
1715681745
1000
0
Show child attributes
Show child attributes
["edge", "edge-eu"]
10
-1
Was this page helpful?