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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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!


My course: Introduction to Developing Power BI Visuals


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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.