Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi,
I am kind of new to the realm of PowerBI, and I am trying to make a real-time dashboard in Power BI service with a dummy dataset.
I am using the streaming dataset module in PowerBi Service and Using the API tab to create a dataset. I defined three variables Date(DateTime), Name(Text) and Marks(Number). And received the following PowerShell API code
$endpoint = "https://api.powerbi.com/beta/f39f15ca-ca8b-4f09-af08-8e6117450991/datasets/c6da6023-0fd5-41fa-ad07-64e8f3505d68/rows?experience=power-bi&clientSideAuth=0&key=EOA9pzRzr%2BtpKXqjI6ludXliGF%2FI8xiiNx6d3Z7yy02STWFAevQWqMXxIySExzMDD70YkVWDmC4oSRIWvj%2Bulg%3D%3D"
$payload = @{
"Date" ="2025-03-04T04:54:52.050Z"
"Name" ="AAAAA555565"
"Marks" =98.6
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
Now I want to create a while loop in this code to auto-update my report and create a real-time dashboard; for this I took the help of ChatGpt to devise a code that can help. I received the following code for this reason.
$endpoint = "https://api.powerbi.com/beta/f39f15ca-ca8b-4f09-af08-8e6117450991/datasets/c6da6023-0fd5-41fa-ad07-64e8f3505d68/rows?experience=power-bi&clientSideAuth=0&key=EOA9pzRzr%2BtpKXqjI6ludXliGF%2FI8xiiNx6d3Z7yy02STWFAevQWqMXxIySExzMDD70YkVWDmC4oSRIWvj%2Bulg%3D%3D"
$refreshEndpoint = "https://api.powerbi.com/v1.0/myorg/datasets/c6da6023-0fd5-41fa-ad07-64e8f3505d68/refreshes"
while ($true) {
# Update data
$payload = @{
"Date" = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") # Current date and time
"Name" = "AAAAA555555"
"Marks" = Get-Random -Minimum 0 -Maximum 100 # Random marks between 0 and 100
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
# Trigger dataset refresh
Invoke-RestMethod -Method Post -Uri "$refreshEndpoint" -Body (ConvertTo-Json @{}) -Headers @{
"Content-Type" = "application/json"
# Include your authorization token here if required
"Authorization" = "Bearer YOUR_ACCESS_TOKEN"
}
Start-Sleep -Seconds 10 # Wait for 10 seconds before the next iteration
}
So, when I punched the code, the following error emerged,
Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
At line:15 char:5
+ Invoke-RestMethod -Method Post -Uri "$refreshEndpoint" -Body (Con ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I checked again and again but couldn't develop any progress. Please help
Solved! Go to Solution.
Can you try below powershell script once. this is working fine for me
"<< API >>"
> while ($true) {
>> $payload = @(
>> @{
>> "Date" = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") # Current UTC DateTime
>> "Name" = "AAAAA555555"
>> "Marks" = Get-Random -Minimum 0 -Maximum 100 # Generate a random number
>> }
>> )
>>
>> $headers = @{
>> "Content-Type" = "application/json"
>> }
>>
>> # Send data to Power BI
>> Invoke-RestMethod -Method Post -Uri "$endpoint" -Headers $headers -Body (ConvertTo-Json $payload -Depth 3)
>>
>> Write-Host "Data sent at $(Get-Date)"
>>
>> Start-Sleep -Seconds 10 # Wait for 10 seconds before the next update
>> }
PFB screenshot for same:
'
Thanks,
Prashanth Are
MS Fabric community support
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query
Can you try below powershell script once. this is working fine for me
"<< API >>"
> while ($true) {
>> $payload = @(
>> @{
>> "Date" = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") # Current UTC DateTime
>> "Name" = "AAAAA555555"
>> "Marks" = Get-Random -Minimum 0 -Maximum 100 # Generate a random number
>> }
>> )
>>
>> $headers = @{
>> "Content-Type" = "application/json"
>> }
>>
>> # Send data to Power BI
>> Invoke-RestMethod -Method Post -Uri "$endpoint" -Headers $headers -Body (ConvertTo-Json $payload -Depth 3)
>>
>> Write-Host "Data sent at $(Get-Date)"
>>
>> Start-Sleep -Seconds 10 # Wait for 10 seconds before the next update
>> }
PFB screenshot for same:
'
Thanks,
Prashanth Are
MS Fabric community support
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query
Hi Prashanth,
It is really helpful for me, can you please guide me how can I make the Power Bi report to update on its own.
with your code, I have to click on the refresh button to update the graph.
Thanks for this immense support