Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Power BI Query - post api request for authenticating and then make api calls

Hi,

 

I'm currently working on UiPath report. API is provided by UiPath to retrive data. It involve 2 steps, 

1. Authenticating, using refresh token and client id.

2. API call to get datd using token from step 1.

 

My query as follows but it does not working

 

let
    token_url = "https://account.uipath.com/oauth/token",    
    api_base_url = "https://platform.uipath.com/AGC/AGC/odata/OrganizationUnits",
    

   body="grant_type=refresh_token&client_id=8DEv1AMNXxxxxxxxxx&refresh_token=BIrTRLxxxxxxxxxx",
   Source  = Json.Document(Web.Contents(token_url,
   [ 
     Headers = [#"Content-Type"="application/json", #"X-UIPATH-TenantName"="AGC"],
     Content=Text.ToBinary(body)
   ]
   )
   ),
    token = Source[access_token],

    data= Json.Document(Web.Contents(api_base_url, [Headers=[#"Authorization"="Bearer "&token, #"Content-Type"="application/json", #"X-UIPATH-TenantName"="AGC"]]))
in
    data

 Is there anything wrong with above query?

 

UiPath provide documentation on how to get data using API https://docs.uipath.com/orchestrator/reference/consuming-cloud-api

 

Any solution or suggestion will be helpful.

 

Thanks,

Ranjith

  • Anonymous's avatar
    Anonymous
    6 years ago

    Thanks Greg...

     

    Just now I get it worked.

     

    The worked query as follows 

     

    let
        token_url = "https://account.uipath.com/oauth/token",    
        api_base_url = "https://platform.uipath.com/AGC/AGC/odata/OrganizationUnits",
        
    
       body="grant_type=refresh_token&client_id=8DEv1AMNXczW3yxxxxxxxxx&refresh_token=BIrTRL7Sqc73ul6M5pEW_xxxxxxxxxxxxxx",
       Source  = Json.Document(Web.Contents(token_url,
       [ 
         Headers = [#"Content-Type"="application/x-www-form-urlencoded", #"X-UIPATH-TenantName"="AGC"],
         Content=Text.ToBinary(body)
       ]
       )
       ),
        token = Source[access_token],
    
        data= Json.Document(Web.Contents(api_base_url, [Headers=[#"Authorization"="Bearer "&token, #"Content-Type"="application/json", #"X-UIPATH-TenantName"="AGC"]]))
    in
        data

     

    And also I set Credentials to 'Anonymous' and Privacy to 'Public'. It works😊

2 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Greg...

       

      Just now I get it worked.

       

      The worked query as follows 

       

      let
          token_url = "https://account.uipath.com/oauth/token",    
          api_base_url = "https://platform.uipath.com/AGC/AGC/odata/OrganizationUnits",
          
      
         body="grant_type=refresh_token&client_id=8DEv1AMNXczW3yxxxxxxxxx&refresh_token=BIrTRL7Sqc73ul6M5pEW_xxxxxxxxxxxxxx",
         Source  = Json.Document(Web.Contents(token_url,
         [ 
           Headers = [#"Content-Type"="application/x-www-form-urlencoded", #"X-UIPATH-TenantName"="AGC"],
           Content=Text.ToBinary(body)
         ]
         )
         ),
          token = Source[access_token],
      
          data= Json.Document(Web.Contents(api_base_url, [Headers=[#"Authorization"="Bearer "&token, #"Content-Type"="application/json", #"X-UIPATH-TenantName"="AGC"]]))
      in
          data

       

      And also I set Credentials to 'Anonymous' and Privacy to 'Public'. It works😊