Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
myusrn
Regular Visitor

power bi > get data > web api > advanced editor > m code to handle http 302 redirects

We have a web api data source that lives behind a cloudfare deployment where http 302 redirects are involved. 

Using power bi desktop > get data > web [ api ] > enter url details and Authorization header value initial produces an access denied.  This was because the services api documentation points to a web api that issues 302 redirects.  If we put the redirect url value in things work fine. Problem is that is a brittle solution and instead we'd like to support following the 302 redirects. 

We have the following code in place that on "Response = Json.Document(InitialRequest)," line is generating the error "Expression.Error: '302' is not supported by the ManualStatusHandling option.".   

Shouldn't 302 be supported and if not any insights on how we properly author web api data source M code to follow a redirect?  


 

let
    // initial request to get the redirect url
    InitialRequest = Web.Contents("https://my.securityjourney.com/api/v3/public-reporting/users", [ManualStatusHandling={302}]),
    //RedirectUrl = Text.FromBinary(InitialRequest[Headers][Location]), // Expression.Error: We cannot apply field access to the type Binary.
    Response = Json.Document(InitialRequest), // Expression.Error: '302' is not supported by the ManualStatusHandling option.
    RedirectUrl = Response[Headers][Location],

    // follow the redirect url to get the actual data
    FinalRequest = Web.Contents(RedirectUrl),
    Source = Json.Document(FinalRequest),

    #"Converted to Table" = Table.FromRecords({Source}),
    #"Expanded users" = Table.ExpandListColumn(#"Converted to Table", "users"),
    #"Expanded users1" = Table.ExpandRecordColumn(#"Expanded users", "users", {"email", "firstName", "lastName", "totalPoints", "securityChampion", "timeSpent"}, {"users.email", "users.firstName", "users.lastName", "users.totalPoints", "users.securityChampion", "users.timeSpent"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded users1",{{"users.email", type text}, {"users.firstName", type text}, {"users.lastName", type text}, {"users.totalPoints", Int64.Type}, {"users.securityChampion", type logical}, {"users.timeSpent", type text}})
in
    #"Changed Type"

 

 

2 REPLIES 2
Anonymous
Not applicable

Hi @myusrn ,

 

The Web.Contents function in Power Query does have some built-in functionality for dealing with HTTP status codes, including 302 redirects. However, it seems that the ManualStatusHandling option does not support 3021.

To handle 302 redirects, you can try the following approach:

  1. Initial Request: Make the initial request and handle the 302 status manually.
  2. Extract Redirect URL: Extracts the redirect URL from the Location header.
  3. Follow Redirect: Make a new request to the redirect URL.

Similar post: Web Connector Redirect - Microsoft Fabric Community

Solved: Power Query Data from Web redirect with cookies (E... - Microsoft Fabric Community

Reference: Handling status codes with Web.Contents for Power Query connectors - Power Query | Microsoft Learn

 

Best Regards,

Stephen Tao

 

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

 

Thanks for the reply and suggestions. As you can see in the power bi m code i shared above i am doing steps 1 thru 3 that you mention above. The issue is that when i get to step 2 it says that the step 1 use of ". . .ManualStatusHandling={302}])," parameter is not supported.  Do you have insights on how else i would "handle the 302 status manually." that is supported?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.