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