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

HTTP Action - URL Redirect

I'm not sure if what I'm trying to do is possible but I thought I'd ask.

 

I have a site where I need to get an XML from, this can be done via their URL (HTTP Action - GET request) however before I can make that GET request, I need to login to the site. 

 

I tried a couple of things and I seem to be able to login via a POST request using Postman. I tried to replicate this in Power Automate (using the HTTP action) however I'm getting the "Object moved to..." error.

 

 

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/ORGANISATION">here</a>.</h2>
</body></html>

 

 

 

After this POST action, I have a GET action which is configured to run when the previous action fails. I thought that even if this POST request fails due to the redirect issue, I now should be logged in and should be able to then make a GET request for the XML file. This proved to be wrong as the GET request returns an error taking me to the site's login page (indicating I have not logged in).

 

I'm assuming I am unable to make the GET request because I have not followed through to the URL redirect in the POST request. 

If I'm assuming wrong, please do let me know. 

 

So my question would be, is it possible for me to get this XML file using Power Automate?

 

Thank you.

 

Here is a screen shot of my Flow, I have removed sensitive information.

Overview of the Flow

API 00.png

 

HTTP Actions Expanded

API 01.pngAPI 02.png

Error Logs

API 03.png

API 04.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Visitor

Replying to my own post because I found my solution and thought I'd share since I struggled to find this online.

 

My post was initially around following a HTTP redirect because I thought this was my issue.

To re-iterate, my first HTTP action was to log in to a system and my second HTTP action was to get a resource (in this case, XML file) from the system I'm logging in to. 

I thought, because I was not following the redirect of the first HTTP action, I am not logging in. I was wrong. Turns out, Power Automate treats each HTTP action in isolation. So my first HTTP action was actually logging in to the system, it's just that my second HTTP action is treated like a new session so that is why I still couldn't get the XML file.

 

I found a way to use the first HTTP action's session in my second HTTP action.

Essentially I just used the cookie provided in the first HTTP action's response and included that cookie in my second HTTP action.

 

The cookie is provided in the HTTP's response header called 'set-cookie'.

I did have to split the 'set-cookie' header to get the part of the cookie that works in my second HTTP action.

 

Here are some screen shots, hopefully this explains in a better way what I am attempting to explain. 

I did use a variable but it's not necessary. The variable does help me convey how this works. 

 

PS: To get the header schema, just run the Flow once (it can fail), then in the log use the output of the header as the sample payload.

Wesso_0-1604557108914.png

Wesso_1-1604557219807.png

 

 

View solution in original post

3 REPLIES 3
Community Support
Community Support

 

Hi @Wesso ,

 

You can copy the url you filled in the URI field to the address bar of your browser to access. If you can download the file, then you can use the HTTP action to get the content of the file in Flow.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-bacao-msft @thanks for the reply. 

If I copy the URL in the GET action, that usually takes me to a login page as I need to be logged in first before I am able to get the XML file. 

The POST request (first HTTP action in my Flow) is doing the log in, however it doesn’t seem to log in properly which I assume is because the Flow cannot handle redirects (but I could be wrong). 

I pretty much tested the same thing in Postman and was able to log in and then get the XML file with the GET request. 

Frequent Visitor

Replying to my own post because I found my solution and thought I'd share since I struggled to find this online.

 

My post was initially around following a HTTP redirect because I thought this was my issue.

To re-iterate, my first HTTP action was to log in to a system and my second HTTP action was to get a resource (in this case, XML file) from the system I'm logging in to. 

I thought, because I was not following the redirect of the first HTTP action, I am not logging in. I was wrong. Turns out, Power Automate treats each HTTP action in isolation. So my first HTTP action was actually logging in to the system, it's just that my second HTTP action is treated like a new session so that is why I still couldn't get the XML file.

 

I found a way to use the first HTTP action's session in my second HTTP action.

Essentially I just used the cookie provided in the first HTTP action's response and included that cookie in my second HTTP action.

 

The cookie is provided in the HTTP's response header called 'set-cookie'.

I did have to split the 'set-cookie' header to get the part of the cookie that works in my second HTTP action.

 

Here are some screen shots, hopefully this explains in a better way what I am attempting to explain. 

I did use a variable but it's not necessary. The variable does help me convey how this works. 

 

PS: To get the header schema, just run the Flow once (it can fail), then in the log use the output of the header as the sample payload.

Wesso_0-1604557108914.png

Wesso_1-1604557219807.png

 

 

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Top Kudoed Authors
Users online (7,604)