cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

REST API - got a token, but when using it, call returns 401 unauthorized

Hi Guys,

 

I was trying to solve my problem by using information form similiar threads on this forum, but can't find an answer there.

 

I'm trying to call the REST API to refresh a PowerBI dataset from Postman (this will be used later in Azure Data Factory). I've:

1. Registered an app (type: Web app / API) using https://dev.powerbi.com/apps

2. Got the grant of the admin for dataset view and read/write

3. Got the token call to work - I receive the bearer token

 

And now when I call the api with the below link, I get 401 unouthorized. Is there anything I might be missing there?

https://api.powerbi.com/v1.0/myorg/datasets/HERE_I_PUT_MY_DATASET/refreshes

 

Regards,

Andy

4 REPLIES 4
Highlighted
Community Support
Community Support

Re: REST API - got a token, but when using it, call returns 401 unauthorized

Hi @AndyFromVolvo 

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

 

Highlighted
New Member

Re: REST API - got a token, but when using it, call returns 401 unauthorized

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

Highlighted
Frequent Visitor

Re: REST API - got a token, but when using it, call returns 401 unauthorized

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?

Highlighted
New Member

Re: REST API - got a token, but when using it, call returns 401 unauthorized

Hi @matdargacz,

 

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/5976/refresh-power-bi-dataset-from-azure-data-factory--part-1...

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

 

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021