Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Refresh API Token every 30 minutes

JM
6 - Meteoroid

I am looking for some examples and help with how to setup an iterative macro to refresh an API token every 30 minutes before passing data into the API for processing.

 

I have a standard workflow that is collecting data to pass into the API currently.  This workflow also generates the initial token and is passing it to the API.  After 30 minutes the token expires and the job fails.

 

I also have a macro to pass the refresh token data into it and to pull back the refreshed token, but it is generating a new token for each set of data being passed vs. reusing the refreshed token value for a duration of 30 minutes.  How can I update the token only once every 30 minutes and to append the value to the data being passed into the API?

11 REPLIES 11
apathetichell
18 - Pollux

Why can't you capture what time you are generaing the token - and then test what time you are hitting the api - if you are at 30 minutes - regenerate - if not - run with the existing token.

BrandonB
Alteryx
Alteryx

DateTimeNow() is a handy function to do what @apathetichell has suggested. I would also highly recommend digging into the API documentation to see if they allow for batch querying. Rather than submitting a bunch of separate API calls you may be able to group them together into much fewer calls which would avoid this issue altogether. 

JM
6 - Meteoroid

I have a timestamp for the token when it is issued and can refresh the token, what I am not sure about is how to refresh the token and append it to the data set yet to be processed within the workflow.  I do not want to refresh the token for every API call and I cannot send batches through to this API as it only accepts a single record at a time.

 

Do you have any suggestions on how to refresh the token and apply it to the unprocessed records?  

sophabraham95
7 - Meteor

is there a sample solution for this that you can share please @apathetichell ? one that does batch processing as well as token regen, so we can better understand your approach on this, thank you.

 

Because, when I have 60 requests, what's happening when i do it is, for the first 30 requests it uses one token, then for the remaining 30 requests as the 15 mins are up, its generating a NEW token for EACH request, am not able to keep the same newly generated token for the next 30.

tim-regas
7 - Meteor

I setup an iterative macro that checks the token each loop to ensure it isn't expired. If the authorization expiration is after now, then it gets diverted to the macro to generate the token and this passes through to the next macro to actually make the API calls. Each iteration the token is checked and only refreshed if it needs to be.Iterative Macro Refresh Token After Expiration.png

apathetichell
18 - Pollux

@sophabraham95 - can you share API specs (ie which API)? It's pretty much impossible to create a workflow like this in the amorphous "show me an example" - especially given that any credentials would be private.

sophabraham95
7 - Meteor

unfortunately, the API is confidential. But just any public API we can take as an example. My issue lies with the token regen alone, not API connectivity.

I am trying to understand how your replacing the existing token with a new one AND retaining the same. Because for me once token 1 expires, for ALL subsequent requests a new token is generated. Which is wasteful.

sophabraham95
7 - Meteor

@tim-regas  right, this is similar to what I've done. But once the first token expires, then for EACH subsequent request the timestamp condition would fail right? and so for all remaining requests, a new auth token is generated EACH time.

tim-regas
7 - Meteor

@sophabraham95 good catch. You are right since it is setup as a batch macro, the auth expiration wouldn't be updated after a new token is generated.

 

We would need to convert it to an iterative macro so that once the token is refreshed, all remaining tokens reflect the updated token. Here is how I would update my previous example to be an iterative macro. Once, the token is expired the remaining records will be filtered to the token generation macro. This will replace the existing token and expiration date and on the next iteration will have the new token and expiration.

Iterative Macro Refresh Token Generation Updated.png

Labels