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
Community Champion
Community Champion

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
Community Champion
Community Champion

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,131)