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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
KR300
Helper III
Helper III

How to write a custom function getting Response from the API or URL. Whether it is Error or Success.

Hi Team, 

Description: My team is publishing a document in the web for each Version( Internally how the Team is doing on the Product development).

Let's say Documents are available in the web ( i am creating dynamic links in the PBI desktop  SFP.R.1.1,  SFP.R.1.2, SFP.R.1.3 ) but not sure when these are published/will publish in web - No perfect date ).

 

So, I need to write a custome function to check or get response from the API or HTTP request. 

 

1. Can we save that response a table in Power BI

2. Based on the response

   If the response is an error or 404 not found -- I need to show Link/URL is not available

   If the response is a success or 200 -- I need to show Link/URL is available    then The USER's/LEADERSHIP directly get to know that informayon whether the URL/Link is available or not, + They will ask the below one why it is not published/ not ready yet.

3 REPLIES 3
KR300
Helper III
Helper III

@nilendraFabric  Thanks for your info. I am getting responses

Status: 404

Message: Link not Available. 

But i want this as a table in power Query so that i can convert likw below for the dynamic purpose

Status          Message

404             Link not Available

nilendraFabric
Community Champion
Community Champion

Hello @KR300 

 

You can create a custom function that calls each URL, checks the HTTP status, and returns a result record to identify whether the link is available or not


read this blog it will be helpful 

 

https://www.tonymcgovern.com/blog/web-api-error-handling/

 

 

Try this

 

(url as text) as record =>
let
response = Web.Contents(url, [ManualStatusHandling={404,400,500}]),
responseStatus = Value.Metadata(response)[Response.Status],
result =
if responseStatus = 200 then
[Status = 200, Message = "Link available"]
else if responseStatus = 404 then
[Status = 404, Message = "Link not available"]
else
[Status = responseStatus, Message = "Other error"]
in
result

 

1.Create a table of Versions and their corresponding hyperlinks.
2. Add a custom column that invokes the above function for each URL.
3. Expand the returned record to see the status code and the custom message.
4. If the status code is 200, you can treat the link as valid. If it is 404, you can display that the link is not yet published.

 

This discussion is helpful as well

 

https://www.reddit.com/r/PowerBI/comments/mm0be7/handling_http_errors_in_webcontents_calls/

 

 

Hope this resolves the query. If yes give kudos and accept the answer 

 

Thanks

@nilendraFabric , Thank you so much you info. Will test it & let you know..

 

Would be great if any .pbix file

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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