Forum Discussion
REST API - got a token, but when using it, call returns 401 unauthorized
Hi Anonymous
Could you show the detailed error message?
Like
Error Message: The remote server returned an error: (401) Unauthorized. Stack Trace:
****
According to this article, to trigger a refresh for the specified dataset from the specified workspace, you could use the following code:
POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetKey}/refreshes
In addition, Please check if you are able to refresh the dataset from Power BI.
Go to Azure Active Directory find the powerbi application to check if you have the permission to refresh.
Best Regards
Maggie
- Anonymous7 years agoNot applicable
Hello Maggie,
Thanks for the quick reply!
The error message I get is: image
I took the trigger from https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/refreshdataset . Now I've tried with the group also, the issue is still the same. I know it's a problem with the permissions, because I get 403 if I provide wrong token, and I get "token expired" if it's too old.
I'm able to refresh it manually, I do it very often. But I'm gettimng the token with client_credentials, so probably the permisions are not passed from my account, but from the app registration. And my app has the Dataset.ReadWrite.All granted by the admin. :(
Regards,
Andy
- Anonymous7 years agoNot applicable
Hello Andy!
I encountered the same issue. I even tried to use https://github.com/microsoft/PowerBI-Developer-Samples but after filling the credentials I also get 401 error. Did you rmanage to esolve this issue?- Anonymous7 years agoNot applicable
Hi Anonymous,
Unfortunately, I still cannot resolve this exact problem. However, for my use case (triggering PowerBI dataset with ADF2 pipeline activity) I've recently found a really useful instruction on how to do that using Logic Apps Custom Connector:
https://www.mssqltips.com/sqlservertip/5979/refresh-power-bi-dataset-using-azure-logic-apps--part-2/
It seems that, after strugginng a bit with that, I was able to finally trigger it just a few moments ago!
But the problem described earlier is still valid - the Postman API call for token works (using the same client ID and secret that I used in the logic apps), but the call for PowerBI refresh API is invalid.
I have a hint, though - the call from Logic Apps that succeeded was in the below format.
{ "host": { "connection": { "name": "/subscriptions/<subscription ID>/resourceGroups/<resource group ID>/providers/Microsoft.Web/connections/<API connection name>" } }, "method": "post", "path": "/v1.0/myorg/groups/<workspace ID>/datasets/<dataset ID>/refreshes" }Where <API connection name> comes from a connection that was auto-generated when I was creating the Logic Apps Custom Connector.
Hope this helps!
Regards,
Andy