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