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
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
Super User
Super User

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