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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
alihassan
Frequent Visitor

Custom visual in Power BI desktop does not make JavaScript http request to third party API

Hi,

We are building a custom visual that needs to make an API call outside the Power BI sandbox to check the license of the user. We use javascript HTTP Request to invoke the third-party API.  It works perfectly fine in Power BI App service but when the same visual used in Power BI Desktop, it does not make that call at all. 

 

This simple API call looks like this

 

 

 

      const req = request(
            {
              host: 'domain.com',
              path: `/api/controller/${key}`,
              method: 'GET',
                },
                response => {
                    response.setEncoding('utf8');
                    if(response.statusCode === 200) {
                        response.on('data', (chunk) => {
                            if (chunk === 'success') {
                              console.log('Success');
                            }
                        });
                    }
            }
          );
       req.end();

 

 

 

 

I was wondering if there is any way to test why the call is not made on desktop or what could be the cause of this issue?

Maybe is there anything that is blocking this call on BI Desktop which works fine on the browser.

 

P.S. There is no restriction on the API side.

 

Any help would be really appreciated,  Thank you.

2 REPLIES 2
dm-p
Super User
Super User

Hi @alihassan,

The only thing I've ever needed to do in these cases was ensure that there were no CORS restrictions on the API-side of things (i.e. allow any origin), otherwise the calls work consistently from either Desktop or Service. I've just tested a couple of these visuals in the September Desktop release, just to be sure and these still work fine from my end.

If that's set-up correctly, then have you ruled out anything specific to the machine running Desktop? Do the calls to the API endpoint work in a tool such as Postman or cURL running on the same machine?

While your API call looks straightforward, the supplied code is provided in isolation from any of the other code in your visual. Is there any other context you can provide? Do you know for sure that the API call code is being reached when you're running it inside Desktop? Do you have any specific packages you're bundling with the compiled visual?

You can't use console.log() in Desktop to debug, but you should be able to alert() your response details, or the error details from a try...catch block as a quick and dirty test to see if there's anything else going on that might fall outside the scope of your current focus (even though you can't alert() in the Service).

Regards,

Daniel

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Hi Daniel,

 

Thank you very much for your detailed answer. Fortunately, I already solved the problem. It did not seem to have an issue with BI Desktop rather API request call was blocked by the Server because of CORS even though, cors were allowed for all incoming calls.

 

Solution: I used javaScript Fetch API and it worked perfectly fine. I still don't know what was causing the cors issue with the previous call but changing to fetch worked for me.

 

Nevertheless, thank you for your answer.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.