Marketo API Token best practices? | Community
Skip to main content
FirstEnt_Develo
Level 2
October 9, 2019
Solved

Marketo API Token best practices?

  • October 9, 2019
  • 1 reply
  • 2452 views

Hi everyone,

I'm building our connection to the API as we're just rolling out Marketo. I had a question about how to handle the token validation. 

Is the best practice to:

- hit the identity endpoint and check for a valid token each time?

- hit the identity endpoint, save when I hit it into a variable, and check if it's been an hour before every call?

- just look for a 601/602 error and if one gets returned, get a new token and try again?

Also, is the validity of the token only checked when my request comes in? As in, if I send a request with 1 second left and it takes 2 seconds, will my request complete successfully? 

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman
  • hit the identity endpoint, save when I hit it into a variable, and check if it's been an hour before every call?
  • just look for a 601/602 error and if one gets returned, get a new token and try again?

A hybrid of these 2.

Definitely do not get a preemptively new token every time -- not only is this crazy overhead, it won't even work because you'll still have a race condition.

Cache the token optimistically and store the approximate age with it. But don't forcibly fetch a new token until it's at least 61 full minutes old. Trying to guess around the exact 60m mark is hopeless -- if it's under 61m, just send the request with the cached token, check for the error, and get a new token then if necessary.

Also, is the validity of the token only checked when my request comes in? As in, if I send a request with 1 second left and it takes 2 seconds, will my request complete successfully?

Yes, it's checked at the outset & the request won't error out in the middle of execution.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
October 9, 2019
  • hit the identity endpoint, save when I hit it into a variable, and check if it's been an hour before every call?
  • just look for a 601/602 error and if one gets returned, get a new token and try again?

A hybrid of these 2.

Definitely do not get a preemptively new token every time -- not only is this crazy overhead, it won't even work because you'll still have a race condition.

Cache the token optimistically and store the approximate age with it. But don't forcibly fetch a new token until it's at least 61 full minutes old. Trying to guess around the exact 60m mark is hopeless -- if it's under 61m, just send the request with the cached token, check for the error, and get a new token then if necessary.

Also, is the validity of the token only checked when my request comes in? As in, if I send a request with 1 second left and it takes 2 seconds, will my request complete successfully?

Yes, it's checked at the outset & the request won't error out in the middle of execution.

FirstEnt_Develo
Level 2
October 9, 2019

Thanks, this was helpful