Forum Discussion
Power BI Rest API Refresh Dataset gives 404 error
HI,
I have created a PowerShell file to refresh the automation of a Power BI dataset. This below snippet worked for a few days and suddenly gave the below error.
VERBOSE: POST https://api.powerbi.com/v1.0/myorg/groups/5fa2e3dc-f8a1-44f1-8f8a-836a531bb0fd/datasets/c9d43a1c-ab7b-4db0-ad72-ce63f9057c69/refreshes with 0-byte payload
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At line:27 char:15
+ ... esultJson = Invoke-RestMethod -Uri $pbiURLapps -Method Post -Headers ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Exception : System.Net.WebException: The remote server returned an error: (404) Not Found.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
InnerException : False
Message : The remote server returned an error: (404) Not Found.
StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
HelpLink :
Source : Microsoft.PowerShell.Commands.Utility
ErrorDetails :
ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 27
The code that I have used as stated below.
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
##Connecting PowerBI
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -Tenant $TenantID
$datasetID = "<DSid>"
$groupID = "<gpid>"
$pbiURLapps = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/datasets/$datasetID/refreshes"
$header = Get-PowerBIAccessToken
$resultJson = Invoke-RestMethod -Uri $pbiURLapps -Method Post -Headers $header -Verbose
I can confirm that dataset ID and group ID is correct. and i have used service principle to do the refresh. Thank you in advance.
This was fixed by adding the relevant AD group to the workspace as a member.
This error happened because the service principle access got revoked without a warning.
8 Replies
- NandanHegdeSuper User
Can you confirm the below 2 aspects:
1) The Service principal is still active in AAD and Access token is getting generated via the SP.
2) The workspace ID and datasetid are still the same? Because in case if you delete the dataset and republish it with same name in same workspace, the datasetid is newly created
- AmilaGunawardanFrequent Visitor
This was fixed by adding the relevant AD group to the workspace as a member.
- AmilaGunawardanFrequent Visitor
Hi,
- I can confirm that Service Principle is active, and access token is generated.
- I have replaced the dataset, but haven't deleted the data set. Because of that, dataset ID was not changed. I have manually checked for any changes of dataset ID.
I will include the Resolve-PowerBIError output below for easier debugging
Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 29 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (403) Forbidden. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (403) Forbidden. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (403) Forbidden. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (403) Forbidden. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : {"Message":"API is not accessible for application"} ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (400) Bad Request. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (400) Bad Request. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 30 Exception : System.Net.WebException: The remote server returned an error: (400) Bad Request. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (400) Bad Request. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 30 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 30 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 30 Exception : System.Net.WebException: The remote server returned an error: (403) Forbidden. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (403) Forbidden. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : {"Message":"API is not accessible for application"} ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 30 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 30 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 29 Exception : System.Net.WebException: The remote server returned an error: (403) Forbidden. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (403) Forbidden. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : {"Message":"API is not accessible for application"} ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 29 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27 Exception : System.Net.WebException: The remote server returned an error: (404) Not Found. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() InnerException : False Message : The remote server returned an error: (404) Not Found. StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() HelpLink : Source : Microsoft.PowerShell.Commands.Utility ErrorDetails : ErrorCategory : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at <ScriptBlock>, <No file>: line 27- AmilaGunawardanFrequent Visitor
This error happened because the service principle access got revoked without a warning.
- AmosHerschMicrosoft Employee
Seems that your service principal lost access to the dataset
- NandanHegdeSuper User
Hey, In case if the access is lost the error messgae would be unauthorized access (401) and not 404.
404 is usually whenever the object you are trying to access doesnt exists.
- AmosHerschMicrosoft Employee
that's not always true. Power BI tries to find the dataset with the credentials of the calling user. If it's not found with those credentials then you might get 404 (not found) error.