cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
deepu299
Frequent Visitor

Bearer Token expires, how to get new token

Hi,

This flow is running perfectly for 3600 secs and fails when the Token expires. How to go back and fetch new token for the flow to continue executing? 

 

This is the HTTP request to get the token: 

https://login.microsoftonline.com/@{TenantID}/oauth2/token

client_id=@{ClientID}&client_Secret=@{ClientSecret}&resource=https://manage.office.com&grant_type=client_credentials

 

Output

{
  "token_type""Bearer",
  "expires_in""3599",
  "ext_expires_in""3599",
  "expires_on""xxx",
  "not_before""xxx",
  "resource""https://manage.office.com",
  "access_token""eyJ0eXAiOiJKV1QiLC...."
}

 

It expires when "Apply to Each" block is running. Since there is no going back to previous step to get new token, what can I do here? 

 

Failure

{
  "Message""Authorization has been denied for this request."
}
 

deepu299_0-1616911008942.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PrasadAthalye
Super User
Super User

You can wrap it in do until something like below... If HTTP calls errors out, generate a new token and set a variable. Note that for Generate Token action, you should change Configure to Run after settings to run only when HTTP Fails.  Then Do until will execute again and HTTP will go through. If no error, exit loop.

 

PrasadAthalye_0-1617062448551.png

 

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

View solution in original post

2 REPLIES 2
PrasadAthalye
Super User
Super User

You can wrap it in do until something like below... If HTTP calls errors out, generate a new token and set a variable. Note that for Generate Token action, you should change Configure to Run after settings to run only when HTTP Fails.  Then Do until will execute again and HTTP will go through. If no error, exit loop.

 

PrasadAthalye_0-1617062448551.png

 

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

Thanks @PrasadAthalye I will try the solution. At this moment, I have increased the concurrency so it is out the action quickly (before 1 hour)

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,187)