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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DaemenBEX
Regular Visitor

Problem with accessing data through API after switching to subaccount

Hi all, 

I am really stuck with loading data in Power BI through an API & would really appreciate any help that could point me in to the right direction. 

 

  • I get my data through an API  and use OAuth to get a token --> got it working fine
  • I have a master account, but need to first switch to a subaccount to get the data from the subaccount--> got ik working fine and api-post-commands returns 'ok' to confirm switch to subaccount
  • But when i use a get-statement to load the data i most of the times only get the data from the parent-account instead of the data from the subaccount  
let
    //********************************************
    // oAUTH-process to generate token
    // Define headerToken as a variabele for API-request
    // Parameters api_url, api_key, api_secret are defined outside query
    
    HeaderToken = "{""api_key"": """ & api_key & """, ""api_secret"": """ & api_secret & """}",

    // Send POST request with headertoken
    // application/json-format / HeaderToken-format in binary format
    
    getToken = Json.Document(Web.Contents(api_url, [Content=Text.ToBinary(HeaderToken), Headers=[#"Content-Type"="application/json"]])),
   
    // getToken returns token
    // getToken[data] returns token as text

    Token= getToken[data],

    // TokenText to transform Token in right format for api call
    
    TokenText="?token=" & Text.From(getToken[data][token]),

    // switch From parent-account to subaccount
    // switchData returns 'ok'

    company_id=10927,
    Switch_parameters= "{""company_id"": " & Text.From(company_id) & "}",
    switch = Json.Document(Web.Contents(switch_account & TokenText, [Content=Text.ToBinary(Switch_parameters), Headers=[#"Content-Type"="application/json"]])),
    switchData = switch[data],

    //********************************************
    // Get the data 
    // Data_url is defined outside query
    
    getData= Json.Document(Web.Contents(data_url & TokenText)),
    data = getData[data]
    
in
    data

 

Why does PowerBI behaves this way? And why does the query above still only returns the data from the parent-account and 'forgets' i switched to a subaccount? Am i missing something obvious here?

 

All help is really appreciated!

 

Grtz, 

 

Bart

1 REPLY 1
Anonymous
Not applicable

Hi @DaemenBEX ,

Firstly, it's important to ensure that the API you're using supports switching contexts between parent and subaccounts seamlessly within the same token session. Some APIs require a new token to be generated specifically for the subaccount after switching, while others maintain the context of the switch within the session of the initial token.

Given the behavior you're experiencing, here are a few things to consider:

1. After switching to the subaccount, does the API documentation indicate if the same token should continue to be used, or is there a need to generate a new token specifically for the subaccount? This is crucial as the token might still be retaining the context of the parent account.

2. After performing the switch to the subaccount, you mentioned receiving an 'ok' response. It might be helpful to verify if the API provides any additional response parameters that confirm the switch context has been updated in the session associated with the token.

3. In some cases, APIs require explicitly specifying the account context (parent or subaccount) in each request after switching. Check if the API requests for retrieving data from the subaccount need any additional parameters or headers that specify the subaccount context.

To further diagnose the issue, I would recommend the following steps:

1. Ensure that the process you're following for switching between accounts and retrieving data aligns with the API's recommended practices. This might include token handling and session management post-switch.

2. Confirm that the API explicitly supports operations on subaccounts in the manner you're attempting. This might be detailed in the API's documentation or support forums.

3. If possible, enable detailed logging for your API requests and responses. This can provide insights into how the API is interpreting your requests post-switch and whether the context is correctly set to the subaccount.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.