Key creation error

Imported Google Group message. Original thread at: Redirecting to Google Groups Import Date: 2016-01-19 21:30:04 +0000.
Sender:Ian Harris.
Date:Thursday, 5 November 2015 16:48:23 UTC.

Hi Martin,

When adding APIs using the Advanced Management API I’ve come across a small problem.

In one of our use cases we add an API and then a key for that API. I’ve noticed when we get to about 16 APIs associated with the adding of a key to an API failes with an error: “Failed to save new session object to Tyk: Could not create key for this API ID, API doesn’t exist.”. However, I have checked the APIs and the API we’re adding does exist.

Having done some testing I’ve noticed the following:

  • add api
  • get that apis internal id by doing a get api
  • add a second api
  • get the second apis internal id
  • add key for api
  • add key for second api (fails)

However, if we move the add of the key to above the add of the second api we get:

  • add api
  • get internal id
  • add key for api (fails)

Is there anything we can do to get around this?

Thanks,
Ian.

Imported Google Group message.
Sender:Martin Buhr.
Date:Thursday, 5 November 2015 17:10:02 UTC.

Hi Ian,

Is the API Keyless? Keyless APIs might cause this issue because they have no storage back-end.

Alternatively, what’s the time difference between adding the API and adding the key? The API, once added, is saved to the DB, and then the Tyk nodes must pick up and load that API after they get the reset command from the bus, only once that happens can you create keys, so if it happens very fast, you may be outrunning the reload logic. Try adding a timer before creating the token.

Also, strictly speaking, you do not need the API ID for each API to create keys, you only need the first one, unless you’ve created your own storage back ends, so try the above again but use the first API ID you create throughout your key adding function.

Many thanks,
Martin

Imported Google Group message.
Sender:Ian Harris.
Date:Thursday, 5 November 2015 17:10:02 UTC.

Hi Ian,

Is the API Keyless? Keyless APIs might cause this issue because they have no storage back-end.

Alternatively, what’s the time difference between adding the API and adding the key? The API, once added, is saved to the DB, and then the Tyk nodes must pick up and load that API after they get the reset command from the bus, only once that happens can you create keys, so if it happens very fast, you may be outrunning the reload logic. Try adding a timer before creating the token.

Also, strictly speaking, you do not need the API ID for each API to create keys, you only need the first one, unless you’ve created your own storage back ends, so try the above again but use the first API ID you create throughout your key adding function.

Many thanks,
Martin

Imported Google Group message.
Sender:Martin Buhr.
Date:Friday, 6 November 2015 14:27:03 UTC.

Hi Martin,

A short delay has resolved the issue. A delay and retry after a failed key add works perfectly.

Thanks,
Ian.

  • show quoted text -