Forum Discussion
Recieving (403) Forbidden when Accessing Dataset via API
Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.
At line:1 char:2
+ Invoke-WebRequest -Uri $url -Method Post -Body $body -Headers $heade ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommandAlright 401 might be different. Make sure the permissions of the registered app at azure have "Dataset.ReadWrite.All" or "Dataset.Read.All".
If you can see the Admin portal or ask for IT department. Please check this setting:
I hope that helps,
- MikeFleming2 years agoRegular Visitor
Hi, yes,
- ibarrau2 years agoSuper User
This might sound weird but please remove the Grant admin consent to the permissions. That's a permission for tenant only that can produce error for regular api requests.
Also add Dataset.ReadWrite.All to keep both permissions for dataset.
Just in case, let's sync something. You are using executeQueries. The request is asking for DAX Query in "My Workspace". If you want to query a dataset in a workspace you must use executeQueries in Group.
Please test "Get Datasets in Group" and let us know if that one works.
Make sure you are not breaking a limitation: https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries-in-group#limitations
Regards.
- MikeFleming2 years agoRegular Visitor
Hi,
I removed the consent, but same
I wasnt aware that was asking for queries in My Workspace. This has worked before with the same code. But I will check that out, and also try the other call you mentioned. I will also revisit the limitations.
Thanks