How to workaround a HTTP 301
Sometimes you come across some nice challenges on the internet. One of them was handling the HTTP 301 response in a Power Automate flow. This short article shows you how you can workaround this.
Shortening services
In this example I will try and process a link which typically will give you a HTTP 301 response. Examples of that are shortening services like Tinyurl, Bitly or Microsoft’s Aka.ms. In this example we will a short link from Microsoft https://aka.ms/ppac, which in a browser will redirect you to the actual long link, https://admin.powerplatform.microsoft.com.
However, like demonstrated in this thread, Power Automate will only give you the MovedPermanently error and will not navigate to the other location. Obviously we want a Power Automate flow to be able to handle this.
The amended concept
After a bit of research I found this nice blog from Erikyadams. I amended his example to specifically work with 301 responses.
Like in his example we are using the location field from the response headers to retry a HTTP request. However, it will only attempt the retry if the first HTTP action has failed (by using run after condition). I have also added a condition action to check for the status code 301. So it won’t run if the first will fail because of other reasons.
The setup
1. Start with a new instant flow with a Manually trigger a flow trigger action.
2. Add a HTTP action. Use the GET method and use https://aka.ms/ppac in the URI field.
3. Add a Condition action. Use the StatusCode field from the previous action. The condition should be StatusCode is equal to 301
4. Click on the ellipses of the Condition action. Click Configure run after
5. Make sure that only the has failed option is checked. Click Done. The arrow above the action should have turned into a dotted red arrow.
6. Add another HTTP action in the Yes branch. Use a GET method and use the following expression for the URI field.
That should be it with the setup. Start testing and let me know if this was useful.
Happy testing!