web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Handling failed http r...
Power Automate
Answered

Handling failed http requests with bearer token having lease time

(0) ShareShare
ReportReport
Posted on by 2 Moderator

Hey,

 

I'm trying to make some flows more robust and efficient.

I have a flow that runs at a specific time every day and loops through up to 1000 iterations.

 

For each iteration, I'm making API calls against a REST API, retrieving a bearer token and then making the api call.

The tokens have a lease time of 3 minutes, so it would be more efficient, if I create two variables (one for the token and one for the ticks when it was created / I have 10 different endpoints, so it will be more like 20 variables) and then have each iteration check if more than 2:40 have passed since the creation of the token and refresh the variables only if needed.

 

Now, my issue is: if the second HTTP action (the actual call I want to make) fails, I want it to check again if too much time has passed. So, the retry policy in Power Automate doesn't cut it.

 

My questions are: How would you solve the token refresh on server errors in the API and do you think working with variables is a good idea, or should I just store the values in a SharePoint list without worrying about the 10 different servers?

Categories:
I have the same question (0)
  • Verified answer
    Pablo Roldan Profile Picture
    316 on at

    How would you solve the token refresh on server errors in the API and do you think working with variables is a good idea, yes it is, but hard to maintain you can create a JSON variable that handles all the tokens, if I understand correctly  each endpoint uses different token so you could try something like this

     

    {
    "token1":{
    "timeStamp":"2024-03-25T17:41:12.9793837Z",
    "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZC...."
    },
    "token2":{
    "timeStamp":"2024-03-25T17:41:12.9793837Z",
    "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZC...."
    }
    }

     

    you can get the ticks comparing with dateDifference() utcNow() and with timeStamp Property, you can also edit that JSON with a compose action using setProperty FX function, 

     

    I'll go by get token, store token, validate if timeStamp is < a 3 min if true call API, maybe you could create a child flow,

    the Http that uses the token I'd set the retry policy None, and I will know that it fail because the token if the response is either 401 | 403, then add parallel branch that Runs After Failed http request and if body http has 

    statusCode 401 | 403 add that request payload to a queue or array within the flow to tried them again

    (you could use childflow)

     

  • schwibach Profile Picture
    2 Moderator on at

    Thanks. That gave me some very good ideas. I think I will use an object variable instead of the text variables.
    I'll have to manage adding the properties for each tenant/server at the start of the flow and then updating them.

     

    Right now, I'm thinking that I won't use a child flow,.
    My current design idea: "do until"-loop with a max counter of 5 and if I get a response 200, it will set the counter to 6, if I get an error, it will increase the counter by 1.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 245

#2
David_MA Profile Picture

David_MA 216 Super User 2026 Season 1

#3
Valantis Profile Picture

Valantis 212

Last 30 days Overall leaderboard