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
EndOfALegacy
New Member

Timeout on a Web.Contents function in custom connector

Hello everyone,

I am currently making a personal SPARQL connector in Power BI. It is mostly basic stuff. I have an interface to enter an Endpoint, a SPARQL Query, and Timeout. I am supposed to display the result in a table in the power bi desktop.

The problem I am having is that the timeout doesn't trigger. If I don't put a LIMIT on the query itself, the program ultimately fails after a few minutes due to a Buffer Overflow. For large datasets, I need to timeout to trigger and the program execution to stop so that I can display whatever results I get. I have checked out previous queries regarding timeouts and I can't seem to find an answer. M script is a completely different field for me so I would really appreciate any help.

Here is my implementation so far:

 

 

DefaultResponseFormat = "json";
DefaultTimeout = 100;
DefaultRetries = 5;
DefaultDelayAPICallRetry = #duration(0,0,0,1/2);

SparqlImpl = (Endpoint as text, Query as text, optional ResponseFormat as text, optional Timeout as number) as table =>
    let
        //ResponseFormat = if ResponseFormat is null then DefaultResponseFormat else ResponseFormat,
        ResponseFormat = DefaultResponseFormat,
        Timeout = if Timeout is null then DefaultTimeout else Timeout,
        Url = Endpoint,
        Table = 
                let
                    response = Value.WaitFor(
                        (iteration) =>
                            let
                                isRetry = if iteration > 0 then true else false,
                                response = Web.Contents(Url,
                                    [   
                                        Query = [
                                            query = Query,
                                            format = ResponseFormat
                                        ],
                                        Timeout = #duration(0, 0, 0, Timeout),
                                        IsRetry = isRetry,
                                        ManualStatusHandling={429}
                                    ]
                                ),
                                buffered = Binary.Buffer(response),
                                status = if buffered = null then 0 else Value.Metadata(response)[Response.Status],
                                actualResult = if status = 429 then null else buffered
                            in
                                actualResult,
                        (iteration) => DefaultDelayAPICallRetry,
                        DefaultRetries
                    ),

                    // Bunch of parsing Code
                    
                in 
                    table
                    
        in 
            Table;


Value.WaitFor = (producer as function, interval as function, optional count as number) as any =>
    let
        list = List.Generate(
            () => {0, null},
            (state) => state{0} <> null and (count = null or state{0} < count),
            (state) => if state{1} <> null then {null, state{1}} else {1 + state{0}, Function.InvokeAfter(() => producer(state{0}), interval(state{0}))},
            (state) => state{1})
    in
        List.Last(list);

 

 

 

3 REPLIES 3
ArghavanA
New Member

Hi, is your query dynamic or static? I mean is the SPARQL query fixed or can the user write their own query and use your PowerBi endpoint. 

amitchandak
Super User
Super User

@EndOfALegacy , Check if pagination can help - https://medium.com/@marktiedemann/how-to-do-pagination-in-power-query-430460c17c78

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Tried it but I cannot append 

"$count=true&$top=0"

to my endpoint Url.  Straight away gives me a 404 because the endpoint can only have a query and format parameter. 
Should be such a simple thing to implement, kind of frustrating.

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.