Create Custom Key / Import Key

POST {{baseUrl}}/tyk/keys/:keyID?suppress_reset=1&hashed=<boolean>

You can use the POST /tyk/keys/{KEY_ID} endpoint as defined below to import existing keys into Tyk.

This example uses standard authorization header authentication, and assumes that the Gateway is located at 127.0.0.1:8080 and the Tyk secret is 352d20ee67be67f6340b4c0605b044b7 - update these as necessary to match your environment.

To import a key called mycustomkey, save the JSON contents as token.json (see example below), then run the following Curl command.

curl http://127.0.0.1:8080/tyk/keys/mycustomkey -H 'x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7' -H 'Content-Type: application/json'  -d @token.json

The following request will fail as the key doesn't exist.

curl http://127.0.0.1:8080/quickstart/headers -H 'Authorization. invalid123'

But this request will now work, using the imported key.

curl http://127.0.0.1:8080/quickstart/headers -H 'Authorization: mycustomkey'

Example token.json file

{
  "allowance": 1000,
  "rate": 1000,
  "per": 60,
  "expires": -1,
  "quota_max": -1,
  "quota_renews": 1406121006,
  "quota_remaining": 0,
  "quota_renewal_rate": 60,
  "access_rights": {
    "3": {
      "api_name": "Tyk Test API",
      "api_id": "3"
    }
  },
  "org_id": "53ac07777cbb8c2d53000002",
  "basic_auth_data": {
    "password": "",
    "hash_type": ""
  },
  "hmac_enabled": false,
  "hmac_string": "",
  "is_inactive": false,
  "apply_policy_id": "",
  "apply_policies": [
    "59672779fa4387000129507d",
    "53222349fa4387004324324e",
    "543534s9fa4387004324324d"
    ],
  "monitor": {
    "trigger_limits": []
  }
}

Request Params

KeyDatatypeRequiredDescription
suppress_resetnumberAdding the suppress_reset parameter and setting it to 1, will cause Tyk not to reset the quota limit that is in the current live quota manager. By default Tyk will reset the quota in the live quota manager (initialising it) when adding a key. Adding the suppress_reset flag to the URL parameters will avoid this behaviour.
hashedstringUse the hash of the key as input instead of the full key

Request Body

{"tags"=>["<string>", "<string>"], "access_rights"=>{"consectetur37"=>{"allowed_urls"=>[{"methods"=>["<string>", "<string>"], "url"=>"<string>"}, {"methods"=>["<string>", "<string>"], "url"=>"<string>"}], "api_id"=>"<string>", "api_name"=>"<string>", "limit"=>{"per"=>"<double>", "quota_max"=>"<long>", "quota_remaining"=>"<long>", "quota_renewal_rate"=>"<long>", "quota_renews"=>"<long>", "rate"=>"<double>", "set_by_policy"=>"<boolean>", "throttle_interval"=>"<double>", "throttle_retry_limit"=>"<long>"}, "versions"=>["<string>", "<string>"]}, "ipsum92"=>{"allowed_urls"=>[{"methods"=>["<string>", "<string>"], "url"=>"<string>"}, {"methods"=>["<string>", "<string>"], "url"=>"<string>"}], "api_id"=>"<string>", "api_name"=>"<string>", "limit"=>{"per"=>"<double>", "quota_max"=>"<long>", "quota_remaining"=>"<long>", "quota_renewal_rate"=>"<long>", "quota_renews"=>"<long>", "rate"=>"<double>", "set_by_policy"=>"<boolean>", "throttle_interval"=>"<double>", "throttle_retry_limit"=>"<long>"}, "versions"=>["<string>", "<string>"]}}, "alias"=>"<string>", "allowance"=>"<double>", "apply_policies"=>["<string>", "<string>"], "apply_policy_id"=>"<string>", "basic_auth_data"=>{"hash_type"=>"<string>", "password"=>"<string>"}, "certificate"=>"<string>", "data_expires"=>"<long>", "enable_detail_recording"=>"<boolean>", "expires"=>"<long>", "hmac_enabled"=>"<boolean>", "hmac_string"=>"<string>", "id_extractor_deadline"=>"<long>", "is_inactive"=>"<boolean>", "jwt_data"=>{"secret"=>"<string>"}, "last_check"=>"<long>", "last_updated"=>"<string>", "monitor"=>{"trigger_limits"=>["<double>", "<double>"]}, "oauth_client_id"=>"<string>", "oauth_keys"=>{"reprehenderit12"=>"<string>", "aliqua110"=>"<string>", "est_f4"=>"<string>", "sunt_00"=>"<string>", "voluptate7af"=>"<string>"}, "org_id"=>"<string>", "per"=>"<double>", "quota_max"=>"<long>", "quota_remaining"=>"<long>", "quota_renewal_rate"=>"<long>", "quota_renews"=>"<long>", "rate"=>"<double>", "session_lifetime"=>"<long>", "throttle_interval"=>"<double>", "throttle_retry_limit"=>"<long>"}

HEADERS

KeyDatatypeRequiredDescription
Content-Typestring
Acceptstring

RESPONSES

status: OK

{&quot;action&quot;:&quot;\u003cstring\u003e&quot;,&quot;key&quot;:&quot;\u003cstring\u003e&quot;,&quot;key_hash&quot;:&quot;\u003cstring\u003e&quot;,&quot;status&quot;:&quot;\u003cstring\u003e&quot;}