# How to deal with APIs and short live tokens

**URL:** <https://forum.ansible.com/t/how-to-deal-with-apis-and-short-live-tokens/26812>\
**Category:** Ansible Project\
**Created:** [February 21, 2018, 12:41pm UTC](https://forum.ansible.com/t/how-to-deal-with-apis-and-short-live-tokens/26812 "2018-02-21T12:41:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcel.liker](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@marcel.liker](https://forum.ansible.com/u/marcel.liker)\
**Post date:** [February 21, 2018, 12:41pm UTC](https://forum.ansible.com/t/how-to-deal-with-apis-and-short-live-tokens/26812/1 "2018-02-21T12:41:25Z")

</div>

Hi all,

I have the following situation which I am not sure how to tackle with ansible.

We have a token API to retrieve auth token using my corporate credentials. Then using this token to authenticate I call another API. However, this second call/task can take some time so I am using the pattern of uri module with until,retries,delay to wait for either success or failure status. Now the token only lives for 5 minutes but waiting for the result of the second call takes usually much longer meaning that after 5 minutes the auth token expires and the task fails.

How does one deal with this scenario? Initially I thought I could use a handler to refresh the token stored in a variable but that does not seem to work.

Example playbook:

`
