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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
novelmayank
Frequent Visitor

Connecting QuickBooks Online to Power BI via API (OAuth2) - Issue with Refreshing Access Token

Hello everyone,

I am attempting to connect QuickBooks Online to Power BI using the API with OAuth2 authentication. I have tried several methods to get the data, including:

  • Power BI Web connector
  • QuickBooks connector
  • Custom connector (this was quite challenging to build, so I might have made some mistakes)
  • Python script

Out of these methods, the Python script has been the most successful. However, I'm facing an issue where I need to manually change the access token every time I want to refresh the data.

I've created a function to fetch a new access token, but when I replace the static access token with this function in my data script, it doesn't work. I have also tried implementing this solution in the Web connector, but without any success.

Has anyone encountered a similar issue or could provide guidance on how to automate the access token refresh process within Power BI? Any help or suggestions would be greatly appreciated.

Thank you!

3 REPLIES 3
Anonymous
Not applicable

Hi @novelmayank ,

May I ask if you were able to successfully connect to QuickBooks via the method provided by @Aryna ?

Hi @novelmayank , I used this Power BI connector and didn't have any issues: https://vidi-corp.com/connect-quickbooks-online-to-power-bi/ 
Some case studies are described there that might be helpful

Best Regards

Aryna
Helper V
Helper V

Hi @novelmayank , I used this Power BI connector and didn't have any issues: https://vidi-corp.com/connect-quickbooks-online-to-power-bi/ 
Some case studies are described there that might be helpful

Anonymous
Not applicable

Hi @novelmayank ,

You can refer the following links to get it:

Refresh the access token in Power BI embedded analytics | Microsoft Learn

Solved: Howe to get API data using Bearer Access Token dyn... - Power Platform Community (microsoft....

Solved: Get token function for API request with dynamic ac... - Microsoft Fabric Community


Here is a quick summary of steps to take:

1. Create static connection to your API using "Authorization" header and format it like "Bearer XXXXX" (It seems you have done this already
2. Create function for like this for querying your token. 

(I am connecting to to PBI rest API in this example: https://login.microsoftonline.com/{{tenant id}}/oauth2/token)

Here is an example of this:


() =>

let

    body = "grant_type=client_credentials&scope=https://analysis.windows.net/powerbi/api/.default&client_id="&client_id&"&client_secret="&client_secret&"&resource="&resource,

    Data =Json.Document(Web.Contents("https://login.microsoftonline.com/"&tenant_id&"/oauth2/token",[Headers=[#"Content-Type"="application/x-www-form-urlencoded"],Content=Text.ToBinary(body)])),

    access_token = Data[access_token]

in

    access_token

 

Code explained:
1st We define what kind of body our request has 
2nd connecting to data using web.contents. Here important thing is Headers

3rd get token


Note: I am using parameters in my code for sensitive data. I recommend this for added security and dynamic options

3. Replace your static token used in step 1 with the function name. E.g. DynamicToken()

Here is an exellent video about this where instead of service principal login (like in my case) they are using username and password: https://youtu.be/N8qYRSqRz84


Best Regards

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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