How to use the Tyk REST API?


#1

Imported Google Group message. Original thread at: https://groups.google.com/forum/#!topic/tyk-community-support/K9pWAlBmfww Import Date: 2016-01-19 21:32:22 +0000.
Sender:Mathijs Van den Worm.
Date:Thursday, 2 April 2015 15:27:39 UTC+1.

Hi there,

I’ve been trying, but seem to be failing non stop, to use your API. As you’ve mentioned in the documentation “The Tyk REST API is the primary means for integrating your application with the Tyk API Gateway server.” The request seem to need more beside a X-Tyk-Authorization header. Could you help me by telling me what I need to send to the API to get a successful result?


#2

Imported Google Group message.
Sender:Martin Buhr.
Date:Thursday, 2 April 2015 15:39:39 UTC+1.

Hi Mathjis,

Sure thing, first off, there’s two API’s (confusing, I know!):

  1. The Tyk gateway REST API (this is documented here)
  2. The Advanced Management API (documented here)

Both API’s allow the same sort of thing (key management, API creation, etc.), however the gateway API is not granular and has a single access token (not good for a larger multi-team implementation, but good for direct integration into your own dashbaord etc.)

The second API is parcelled with the dashboard (and so is on a different port), to use this API you need to use the access token for the user that was created during setup, and the header is different.

Here’s a CURL sample for the gateway REST API:

curl http://HOST:PORT/tyk/keys/create
–header "x-tyk-authorization: "
–data ‘{
“allowance”: 1000,
“rate”: 1000,
“per”: 60,
“expires”: 0,
“quota_max”: -1,
“quota_renews”: 1406121006,
“quota_remaining”: 0,
“quota_renewal_rate”: 60,
“access_rights”: {
“”: {
“api_name”: “My Test API”,
“api_id”: “”,
“versions”: [
“Default”
]
}
},
“org_id”: “”
}’

For the advanced API, you would use something that looked more like this:

curl http://HOST:PORT/api/keys
–header "authorization: "
–data ‘{
“last_check”: 0,
“allowance”: 1000,
“rate”: 1000,
“per”: 60,
“expires”: 1430505313,
“quota_max”: -1,
“quota_renews”: 1427985366,
“quota_remaining”: -1,
“quota_renewal_rate”: 60,
“access_rights”: {
“b605a6f03cc14f8b74665452c263bf19”: {
“api_id”: “b605a6f03cc14f8b74665452c263bf19”,
“api_name”: “Tyk Test API”,
“versions”: [
“Default”
]
}
}
}’

So the first question would be, which API are you targetting?

Cheers,
Martin

On Thursday, April 2, 2015 at 3:27:39 PM UTC+1, Mathijs Van den Worm wrote:
Hi there,

I’ve been trying, but seem to be failing non stop, to use your API. As you’ve mentioned in the documentation “The Tyk REST API is the primary means for integrating your application with the Tyk API Gateway server.” The request seem to need more beside a X-Tyk-Authorization header. Could you help me by telling me what I need to send to the API to get a successful result?


#3

Imported Google Group message.
Sender:Mathijs Van den Worm.
Date:Thursday, 2 April 2015 15:39:39 UTC+1.

Hi Mathjis,

Sure thing, first off, there’s two API’s (confusing, I know!):

  1. The Tyk gateway REST API (this is documented here)
  2. The Advanced Management API (documented here)

Both API’s allow the same sort of thing (key management, API creation, etc.), however the gateway API is not granular and has a single access token (not good for a larger multi-team implementation, but good for direct integration into your own dashbaord etc.)

The second API is parcelled with the dashboard (and so is on a different port), to use this API you need to use the access token for the user that was created during setup, and the header is different.

Here’s a CURL sample for the gateway REST API:

curl http://HOST:PORT/tyk/keys/create
–header "x-tyk-authorization: "
–data ‘{
“allowance”: 1000,
“rate”: 1000,
“per”: 60,
“expires”: 0,
“quota_max”: -1,
“quota_renews”: 1406121006,
“quota_remaining”: 0,
“quota_renewal_rate”: 60,
“access_rights”: {
“”: {
“api_name”: “My Test API”,
“api_id”: “”,
“versions”: [
“Default”
]
}
},
“org_id”: “”
}’

For the advanced API, you would use something that looked more like this:

curl http://HOST:PORT/api/keys
–header "authorization: "
–data ‘{
“last_check”: 0,
“allowance”: 1000,
“rate”: 1000,
“per”: 60,
“expires”: 1430505313,
“quota_max”: -1,
“quota_renews”: 1427985366,
“quota_remaining”: -1,
“quota_renewal_rate”: 60,
“access_rights”: {
“b605a6f03cc14f8b74665452c263bf19”: {
“api_id”: “b605a6f03cc14f8b74665452c263bf19”,
“api_name”: “Tyk Test API”,
“versions”: [
“Default”
]
}
}
}’

So the first question would be, which API are you targetting?

Cheers,
Martin

On Thursday, April 2, 2015 at 3:27:39 PM UTC+1, Mathijs Van den Worm wrote:
Hi there,

I’ve been trying, but seem to be failing non stop, to use your API. As you’ve mentioned in the documentation “The Tyk REST API is the primary means for integrating your application with the Tyk API Gateway server.” The request seem to need more beside a X-Tyk-Authorization header. Could you help me by telling me what I need to send to the API to get a successful result?


#4

Imported Google Group message.
Sender:Martin Buhr.
Date:Friday, 3 April 2015 08:17:31 UTC+1.

Thanks for replying, the Tyk gateway REST API is the one I needed.

Op donderdag 2 april 2015 16:39:39 UTC+2 schreef Martin Buhr:

  • show quoted text -

#5

Imported Google Group message.
Sender:Mathijs Van den Worm.
Date:Tuesday, 1 December 2015 10:40:48 UTC.

Is the the “Tyk Dashboard API Access Credentials” key on the Dashboard admin users page?
I used that (and also with tyk secret) to get the portal developers but it returned “Not authorized”.
“curl -i -H “Authorization: {access_key}” -X GET http://localhost:3000/api/portal/developers

  • show quoted text -

#6

Imported Google Group message.
Sender:Mathijs Van den Worm.
Date:Tuesday, 1 December 2015 11:10:01 UTC.

Hi Tarmo,

Yes it is, you may need to recreate it if it isn’t working…

Cheers,
Martin