Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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
v-juanli-msft
Community Support
Community Support

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

 

Anonymous
Not 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

Anonymous
Not 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?

Anonymous
Not 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/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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors