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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.