Forum Discussion

minasexc's avatar
minasexc
Regular Visitor
4 years ago
Solved

API Authorization Issue

Hello guys,

 

I have the below API which is running smoothly.

 

Then, I'm copying the token and I am insterting it to the next API, which still runs just fine. 

 

 

But, when I'm trying to make it dynamically, then it throws error.

 

Seems ok until second step. 

 

And the error at the third step. 

 

 

 

Any idea how to solve this? 

 

Thxx

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi minasexc ,

     

    1. Get Access token in Power BI Desktop:

     

    () =>
    
     
    
    let
    
        body = "client_id=" & #"App ID"
    
        & "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret"
    
        & "&grant_type=client_credentials",
    
        Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/",
    
        [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
    
        access_token = Data[access_token]
    
    in
    
        access_token

    OR

    () =>
    
     
    
    let
    
        body =  "&grant_type=Password&resource = https://analysis.windows.net/powerbi/api
    
    &client_id=*****&username=*****&password=*****",
    
        
     Data=Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/v2.0/token/",
    
        [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
    
        access_token = Data[access_token]
    
    in
    
        access_token

     

    2.

    You can replace bear token by the access token parameter. It will refresh every time your refresh your report.

    Video: How to get access token and call Rest API by dynamic access token in Power BI Desktop? (5:30 to 9:30)

    all Power BI Rest API with Dynamic Access Token From Power BI Desktop |Power BI Rest API

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi minasexc ,

     

    1. Get Access token in Power BI Desktop:

     

    () =>
    
     
    
    let
    
        body = "client_id=" & #"App ID"
    
        & "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret"
    
        & "&grant_type=client_credentials",
    
        Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/",
    
        [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
    
        access_token = Data[access_token]
    
    in
    
        access_token

    OR

    () =>
    
     
    
    let
    
        body =  "&grant_type=Password&resource = https://analysis.windows.net/powerbi/api
    
    &client_id=*****&username=*****&password=*****",
    
        
     Data=Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/v2.0/token/",
    
        [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
    
        access_token = Data[access_token]
    
    in
    
        access_token

     

    2.

    You can replace bear token by the access token parameter. It will refresh every time your refresh your report.

    Video: How to get access token and call Rest API by dynamic access token in Power BI Desktop? (5:30 to 9:30)

    all Power BI Rest API with Dynamic Access Token From Power BI Desktop |Power BI Rest API

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • minasexc's avatar
    minasexc
    Regular Visitor

    Hi,

     

    Thank you so much for the help.

     

    Now, it works just fine. 

     

    Minas