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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
q2bi
Frequent Visitor

What is the perfect way to access my back-end api with authentication in PowerBI custom visual?

 
3 REPLIES 3
Anonymous
Not applicable

Hi @q2bi ,

 

I think you may want to use Visual API in your custom visual. I suggest you to refer to below offical blogs.

For reference:
Visual API for Power BI Visuals - Power BI | Microsoft Learn
Power BI visual project structure - Power BI | Microsoft Learn

Local Storage API in Power BI Visuals - Power BI | Microsoft Learn

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymous  Hi! Is there any solution to this issue?

No, i want to send http post request in my custom visual like this. 

 

 

 

 

const url = 'https://www.mycompany.com/api/v1/comment/save';
const username = 'company_username';
const password = 'company_password';

const headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa(username + ":" + password));
headers.set('Content-Type', 'application/json');

const data = {
    comment: 'This is a sample comment',
    userId: 12345
};

fetch(url, {
    method: 'POST',
    headers: headers,
    body: JSON.stringify(data)
})

 

 

 

This request needs authentication but it's unsafe to write the username and password at BI visual project code and different customer has different Microsoft account so it's impossible to write an account name and password in the code. The most important ,my customer has login his Microsoft account to access my PowerBI report and i can't ask him to login my company auth account.
 
I have tried to get Microsoft AccessToken and send it to my API as header authorization parameter,  it works in development environment. The official document told me that the visual should be publish in product environment but the visual will be disabled Web Access Privilege that the http request will be disabled. 

 

 

https://learn.microsoft.com/en-us/power-bi/developer/visuals/power-bi-custom-visuals-certified#not-a...

 

 

Is there any ideas to access my api safely ? Setting API username and password in PowerBI Gateway connection then BI visual connects the Gateway connection? or anyother user token that i can get no need to publish the BI visual ? 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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