Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi,
I've read that you can create custom visuals with a button that will POST to a rest API. I want to use this to update our database via a REST API from our Power BI Report in our Embedded workspace.
I've used the below TypeScript code, but each time I click the button, I get a "TypeError: Failed to Fetch" message.
I can't use PowerApps to do this, as our customers use the Report and so they do not all have the logins needed for Power Apps authentication (even when using a Per App Licence).
Any help would be much appreciated.
Lee.
private onButtonClick(): void {
// Prepare the payload; include values extracted from the model
const payload = {
Value: "98"
};
const json = JSON.stringify(payload)
this.button.innerText = json
const apiUrl = "http://localhost:5000/log/";
fetch(apiUrl, {
method: "POST"
,
headers: {
"Content-Type": "application/json"
}
,
body: json
})
.then(response => {
if (!response.ok) {
this.button.innerText = `API call failed: ${response.statusText}`;
}
return response.json();
})
.then(data => {
this.button.innerText = data;
})
.catch(error => {
this.button.innerText = error;
});
Solved! Go to Solution.
Hi,
Thanks for the advice/help. I did have most of that in place, but not all of it.
I do now have it working, and the two main things causing the issues were not using HTTPS and also not realising you have to amend the "Capabilites.json" file to include your REST API URL in the privileges section, as shown below.
"privileges": [
{
"name": "WebAccess",
"essential": true,
"parameters": [
"https://leetest.free.beeceptor.com",
]
}
]
Hi,
Thanks for the advice/help. I did have most of that in place, but not all of it.
I do now have it working, and the two main things causing the issues were not using HTTPS and also not realising you have to amend the "Capabilites.json" file to include your REST API URL in the privileges section, as shown below.
"privileges": [
{
"name": "WebAccess",
"essential": true,
"parameters": [
"https://leetest.free.beeceptor.com",
]
}
]
Hi @LPAN012345 ,
Based on your description and codes, this error is commonly related to a cross-origin issue (or similar network problems) when running your fetch() call from within a Power BI custom visual. Could you please check the following info?
const cors = require('cors'); app.use(cors()); |
Modify your fetch
call to include CORS parameters
fetch(apiUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: json, mode: "cors", // Explicitly enable CORS credentials: "omit" // Adjust based on your auth requirements }) |
Best Regards
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
6 | |
2 | |
2 | |
2 |
User | Count |
---|---|
4 | |
4 | |
4 | |
4 | |
4 |