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
haiyangl104
Frequent Visitor

Https 401 Unauthorized Post Request for Refreshing Power BI datasets using REST API via Python

I experience the following error when trying to refresh my Power BI dataset in a particular workspace via Python:

 

haiyangl104_0-1622658846628.png

 

I've followed this guide online and registered Power BI as "Native App" in Azure Active Directory>App Registrations:

Automate Your Power BI Dataset Refresh with Python - Pivotal BI

 

Under "Azure Active Directory>App Registrations", our Azure Admin provisioned the following API permissions from the guide:

 

haiyangl104_1-1622660756509.png

 

In Power BI Web Services, I've configured the Data Source credentials correctly:

 

haiyangl104_2-1622660866858.png

 

Despite following all the steps exactly from the guide, refreshing the dataset via Power BI API post request does not work. Strangely, manually clicking refresh button on Power BI desktop and Power BI web services do work.

 

Any help is appreciated!

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @haiyangl104,

>>After digging deeper, I found out that my Power BI Pro licensed account is on the Gov Cloud, with address of

It sounds like you are working with GOV cloud.

Currently, we do not have permission to test with these types of resources. I'd like to suggest you open a support ticket to power bi team for further supports.

submit a support ticketsubmit a support ticket

Support | Microsoft Power BI

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

11 REPLIES 11
v-shex-msft
Community Support
Community Support

HI @haiyangl104,

I found you use the f format string in these steps, have you try to concatenate strings with delimiter or use static values to test and send requests?

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Yes, I've tried using static values in the refresh_url path but still no luck:

haiyangl104_0-1623082527471.png

 

Hi @haiyangl104,

If you test on the same variables on documents online testing(REST API document -> try it), did these API works?

I'd like to confirm if your credentials are available for the rest API usage. 

Datasets - Refresh Dataset In Group - REST API (Power BI Power BI REST APIs) | Microsoft Docs

Notice: 401 error seems related to request credentials.

401 Unauthorized - HTTP | MDN (mozilla.org)

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

The tool you've posted is incredibly helpful! I found out the issue: My Azure account (john.doe@abc) and Power BI Pro licensed account (john.doe@xyz) have two different domain names. Because I'm sending HTTPS post request from my Azure account, the error code is saying that the account does not have Power BI Pro License. Do you have any suggestions for authorizing dataset refresh post request from a different Azure account? Our organization's IT department chose to de-couple our Power BI accounts and our Azure accounts, which is outside of my control.

Hi @haiyangl104,

So you mean your accounts are split into different parts and the current one which you used only has permission to operate power bi contents not has permission to operate these APIs?

If that is the case, you can consider using the azure b2b feature to share the permission to access these contents if it works for the rest API usages.

Distribute content to external guest users with Azure AD B2B - Power BI | Microsoft Docs

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

After digging deeper, I found out that my Power BI Pro licensed account is on the Gov Cloud, with address of "https://app.powerbigov.us/". I noticed that the Power BI REST API documentation only have "https://api.powerbi.com" which is for commercial users. I looked online for GCC version of API by switching to: "https://api.powerbigov.us"  but it gives me back the following error:

 

HTTPError: 403 Client Error: Forbidden for url: https://api.powerbigov.us/v1.0/myorg/groups

Hi @haiyangl104,

>>After digging deeper, I found out that my Power BI Pro licensed account is on the Gov Cloud, with address of

It sounds like you are working with GOV cloud.

Currently, we do not have permission to test with these types of resources. I'd like to suggest you open a support ticket to power bi team for further supports.

submit a support ticketsubmit a support ticket

Support | Microsoft Power BI

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

For some reason clicking on "Create support ticket" says I don't have a Power BI Pro License:

haiyangl104_0-1623782857664.png

 

But I do have a Pro license under Power BI Gov Cloud (app.powerbigov.us):

haiyangl104_1-1623783059773.png

 

Is there any other way to get around this problem?

Hi @haiyangl104m

I'd like to suggest you submit a ticket with your gov account with 'support ticket' or 'national cloud' mode.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Any news?

I have the same issue

 

FYI, after working with Microsoft Support, it was discovered that our Power platform is on US-Gov Texas, and Power BI REST API was being called from Azure-Commercial US-East Databricks Workspace using Python requests library. We were unable to authenticate via Azure AD for the REST API because our Power Platform and Azure Databricks Workspace are under different regions. We were advised by Microsoft to migrate our Power Platform to US-East via support ticket to align the regions, however, our organization's management have not made the decision due to uncertainty from the migration impact. 

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.