Power BI Connector for UiPath : Make generic REST API request via SQL

Integrate UiPath and Power BI
Integrate UiPath and Power BI

Learn how to make generic REST API request using the Power BI Connector for UiPath. This connector enables you to read and write Microsoft Power BI data effortlessly. Access, refresh, and manage datasets, reports, and dashboards — almost no coding required. We'll walk you through the exact setup.

Let's dive in!

Create data source using Power BI ODBC Driver

  1. Download and install ODBC PowerPack (if you haven't already).

  2. Search for odbc and open the ODBC Data Sources (64-bit):

    Open ODBC Data Source
  3. Create a User data source (User DSN) based on the ZappySys API Driver driver:

    ZappySys API Driver
    Create new User DSN for ZappySys API Driver
    • Create and use a User DSN if the client application runs under a User Account. This is the ideal option at design time (e.g., when developing in Visual Studio). Use it for both types of applications (64-bit and 32-bit).
    • Create and use a System DSN if the client application runs under a System Account (e.g., as a Windows Service). This is usually the required option in a production environment. If your Windows Service is a 32-bit application, you must use the 32-bit ODBC Data Source Administrator to configure this
  4. When the Configuration window appears give your data source a name if you haven't done that already, then select "Power BI" from the list of Popular Connectors. If "Power BI" is not present in the list, then click "Search Online" and download it. Then set the path to the location where you downloaded it. Finally, click Continue >> to proceed with configuring the DSN:

    PowerBiDSN
    Power BI
    ODBC DSN Template Selection
  5. Now it's time to configure the Connection Manager. Select Authentication Type, e.g. Token Authentication. Then select API Base URL (in most cases, the default one is the right one). More info is available in the Authentication section.

    Power BI authentication

    Use delegated access (User Credentials) whenever you want to let a signed-in user work with their own resources or resources they can access. Whether it's an admin setting up policies for their entire organization or a user deleting an email in their inbox, all scenarios involving user actions should use delegated access. [API reference]

    Follow these simple steps below to create Microsoft Entra ID application with delegated access:

    WARNING: If you are planning to automate processes, we recommend that you use a Application Credentials authentication method. In case, you still need to use User Credentials, then make sure you use a system/generic account (e.g. automation@my-company.com). When you use a personal account which is tied to a specific employee profile and that employee leaves the company, the token may become invalid and any automated processes using that token will start to fail.
    1. Navigate to the Azure Portal and log in using your credentials.
    2. Access Microsoft Entra ID.
    3. Register a new application by going to App registrations and clicking on New registration button:

      Start new app registration in Microsoft Entra ID
      INFO: Find more information on how to register an application in Graph API reference.
    4. When configuration window opens, configure these fields:

      • Supported account type
        • Use Accounts in this organizational directory only, if you need access to data in your organization only.
      • Redirect URI:
        • Set the type to Public client/native (mobile & desktop).
        • Use https://zappysys.com/oauth as the URL.
      Register app in Microsoft Entra ID
    5. After registering the app, copy the Application (client) ID for later:

      Copy client ID of Microsoft Entra ID app
    6. Copy OAuth authorization endpoint (v2) & OAuth token endpoint (v2) URLs to use later in the configuration:

      Copy Auth and Token URLs in Microsoft Entra ID app
    7. Now go to SSIS package or ODBC data source and use the copied values in User Credentials authentication configuration:

      • In the Authorization URL field paste the OAuth authorization endpoint (v2) URL value you copied in the previous step.
      • In the Token URL field paste the OAuth token endpoint (v2) URL value you copied in the previous step.
      • In the Client ID field paste the Application (client) ID value you copied in the previous step.
      • In the Scope field use the default value or select individual scopes, e.g.:
        • offline_access
        • https://analysis.windows.net/powerbi/api/Workspace.Read.All
        • https://analysis.windows.net/powerbi/api/Dataset.Read.All
        • https://analysis.windows.net/powerbi/api/Dataset.ReadWrite.All
    8. Press Generate Token button to generate Access and Refresh Tokens.
    9. Click Test Connection to confirm the connection is working.
    10. Optional step. Choose Default Workspace from the drop down menu.
    11. Choose Default Dataset from the drop down menu.
    12. Done! Now you are ready to use the API Connector!
    API Connection Manager configuration

    Just perform these simple steps to finish authentication configuration:

    1. Set Authentication Type to User Credentials [OAuth]
    2. Optional step. Modify API Base URL if needed (in most cases default will work).
    3. Fill in all the required parameters and set optional parameters if needed.
    4. Press Generate Token button to generate the tokens.
    5. Finally, hit OK button:
    PowerBiDSN
    Power BI
    User Credentials [OAuth]
    https://api.powerbi.com/v1.0/myorg
    Required Parameters
    Authorization URL Fill-in the parameter...
    Token URL Fill-in the parameter...
    Client ID Fill-in the parameter...
    Scope Fill-in the parameter...
    Default Dataset (select after generating tokens) Fill-in the parameter...
    Optional Parameters
    Client Secret
    Redirect URI (must match App Redirect URI)
    Default Workspace (Keep Empty for My Workspace - select after generating tokens)
    RetryMode RetryWhenStatusCodeMatch
    RetryStatusCodeList 429|503
    RetryCountMax 20
    RetryWaitTimeMs 1000
    RetryMultiplyWaitTime True
    Login options
    ODBC DSN OAuth Connection Configuration

  6. Then go to Preview tab to start building a SQL query.

  7. Once you do that, proceed by opening Query Builder:

    ZappySys API Driver - Power BI
    Read and write Microsoft Power BI data effortlessly. Access, refresh, and manage datasets, reports, and dashboards — almost no coding required.
    PowerBiDSN
    Open Query Builder in API ODBC Driver to read and write data to REST API
  8. Then simply select the Make Generic REST API Request endpoint (action).

  9. Continue by configuring the Required parameters. You can also set optional parameters too.

  10. Move on by hitting Preview Data button to preview the results.

  11. If you see the results you need, simply copy the generated query:

    Make Generic REST API Request
    Required Parameters
    HTTP - Url or File Path Select the value from the dropdown
    Optional Parameters
    HTTP - Request Body
    HTTP - Is MultiPart Body (Pass File data/Mixed Key/value)
    HTTP - Headers (e.g. hdr1:aaa || hdr2:bbb) Accept: */* || Cache-Control: no-cache
    Parser - Filter (e.g. $.rows[*] )
    Download - Enable reading binary data False
    Download - File overwrite mode AlwaysOverwrite
    Download - Save file path
    Download - Enable raw output mode as single row False
    Download - Raw output data RowTemplate {Status:'Downloaded'}
    Download - Request Timeout (Milliseconds)
    Advanced Properties
    HTTP - Request Method GET
    HTTP - Request Format (Content-Type) ApplicationJson
    Parser - Response Format (Default=Json) Default
    Parser - Encoding
    Parser - CharacterSet
    General - Enable Custom Search/Replace
    General - SearchFor (e.g. (\d)-(\d)--regex)
    General - ReplaceWith (e.g. $1-***)
    General - File Compression Type
    General - Date Format
    General - Enable Big Number Handling False
    General - Wait time (Ms) - Helps to slow down pagination (Use for throttling) 0
    JSON/XML - ExcludedProperties (e.g. meta,info)
    JSON/XML - Flatten Small Array (Not preferred for more than 10 items)
    JSON/XML - Max Array Items To Flatten 10
    JSON/XML - Array Transform Type
    JSON/XML - Array Transform Column Name Filter
    JSON/XML - Array Transform Row Value Filter
    JSON/XML - Array Transform Enable Custom Columns
    JSON/XML - Enable Pivot Transform
    JSON/XML - Array Transform Custom Columns
    JSON/XML - Pivot Path Replace With
    JSON/XML - Enable Pivot Path Search Replace False
    JSON/XML - Pivot Path Search For
    JSON/XML - Include Pivot Path False
    JSON/XML - Throw Error When No Match for Filter False
    JSON/XML - Parent Column Prefix
    JSON/XML - Include Parent When Child Null False
    Pagination - Mode
    Pagination - Attribute Name (e.g. page)
    Pagination - Increment By (e.g. 100) 1
    Pagination - Expression for Next URL (e.g. $.nextUrl)
    Pagination - Wait time after each request (milliseconds) 0
    Pagination - Max Rows Expr
    Pagination - Max Pages Expr
    Pagination - Max Rows DataPath Expr
    Pagination - Max Pages 0
    Pagination - End Rules
    Pagination - Next URL Suffix
    Pagination - Next URL End Indicator
    Pagination - Stop Indicator Expr
    Pagination - Current Page
    Pagination - End Strategy Type DetectBasedOnRecordCount
    Pagination - Stop based on this Response StatusCode
    Pagination - When EndStrategy Condition Equals True
    Pagination - Max Response Bytes 0
    Pagination - Min Response Bytes 0
    Pagination - Error String Match
    Pagination - Enable Page Token in Body False
    Pagination - Placeholders (e.g. {page})
    Pagination - Has Different NextPage Info False
    Pagination - First Page Body Part
    Pagination - Next Page Body Part
    Csv - Column Delimiter ,
    Csv - Has Header Row True
    Csv - Throw error when column count mismatch False
    Csv - Throw error when no record found False
    Csv - Allow comments (i.e. line starts with # treat as comment and skip line) False
    Csv - Comment Character #
    Csv - Skip rows 0
    Csv - Ignore Blank Lines True
    Csv - Skip Empty Records False
    Csv - Skip Header Comment Rows 0
    Csv - Trim Headers False
    Csv - Trim Fields False
    Csv - Ignore Quotes False
    Csv - Treat Any Blank Value As Null False
    Xml - ElementsToTreatAsArray
    SELECT * 
    FROM generic_request
    WITH (Url='/groups',
    Filter='$.value[*]')
    
    
    /*
    EXPLANATION:
    - This configuration calls Power BI REST API "Get Groups" endpoint and gets the Workspaces back.
    - This is achieved by "/groups" value in the "Url" parameter.
    - The SQL query parameter "Filter" uses JsonPath "$.value[*]".
    - This gets JSON objects from "value" array and transforms them into SQL rows.
    
    MORE INFORMATION:
    - About "Get Groups" REST API endpoint:
      https://learn.microsoft.com/en-us/rest/api/power-bi/groups/get-groups
    - About JsonPath used in "Filter" parameter:
      https://zappysys.com/blog/jsonpath-examples-expression-cheetsheet  
    */
    Query Builder
  12. Click OK to use built SQL query and close the Query Builder.

  13. Now hit Preview Data button to preview the data using the generated SQL query. If you are satisfied with the result, use this query in UiPath:

    ZappySys API Driver - Power BI
    Read and write Microsoft Power BI data effortlessly. Access, refresh, and manage datasets, reports, and dashboards — almost no coding required.
    PowerBiDSN
    SELECT * 
    FROM generic_request
    WITH (Url='/groups',
    Filter='$.value[*]')
    
    
    /*
    EXPLANATION:
    - This configuration calls Power BI REST API "Get Groups" endpoint and gets the Workspaces back.
    - This is achieved by "/groups" value in the "Url" parameter.
    - The SQL query parameter "Filter" uses JsonPath "$.value[*]".
    - This gets JSON objects from "value" array and transforms them into SQL rows.
    
    MORE INFORMATION:
    - About "Get Groups" REST API endpoint:
      https://learn.microsoft.com/en-us/rest/api/power-bi/groups/get-groups
    - About JsonPath used in "Filter" parameter:
      https://zappysys.com/blog/jsonpath-examples-expression-cheetsheet  
    */
    API ODBC Driver-based data source data preview
    You can also access data quickly from the tables dropdown by selecting <Select table>.
    A WHERE clause, LIMIT keyword will be performed on the client side, meaning that the whole result set will be retrieved from the Power BI API first, and only then the filtering will be applied to the data. If possible, it is recommended to use parameters in Query Builder to filter the data on the server side (in Power BI servers).

Let's not stop here and explore SQL query examples, including how to use them in Stored Procedures and Views (virtual tables) in the next steps.

Power BI SQL query examples

Use these SQL queries in your UiPath data source:

Call generic API request

Calls a generic Power BI API endpoint. Supply the endpoint path in the Url parameter.

SELECT * 
FROM generic_request
WITH (Url='/groups',
Filter='$.value[*]')


/*
EXPLANATION:
- This configuration calls Power BI REST API "Get Groups" endpoint and gets the Workspaces back.
- This is achieved by "/groups" value in the "Url" parameter.
- The SQL query parameter "Filter" uses JsonPath "$.value[*]".
- This gets JSON objects from "value" array and transforms them into SQL rows.

MORE INFORMATION:
- About "Get Groups" REST API endpoint:
  https://learn.microsoft.com/en-us/rest/api/power-bi/groups/get-groups
- About JsonPath used in "Filter" parameter:
  https://zappysys.com/blog/jsonpath-examples-expression-cheetsheet  
*/

Call generic API request with URL parameters

Calls a generic Power BI API endpoint with URL parameters (e.g. filters). Supply the endpoint path and parameters in the Url parameter.

SELECT * 
FROM generic_request
WITH (Url='/groups?$filter=contains(name,''MyWorkspace'') or name eq ''My Blue Workspace''',
Filter='$.value[*]')


/*
EXPLANATION:
- This configuration calls Power BI REST API "Get Groups" endpoint and gets the Workspaces back.
- This is achieved by "/groups" value in the "Url" parameter.
- Workspaces are filtered on the Power BI REST API side by using the "$filter" URL parameter.
- Only those Workspaces are returned that:
  > contain a string value "MyWorkspace" or
  > if the Workspace name is "My Blue Workspace" (each single quote is escaped with two single quotes).
- The SQL query parameter "Filter" uses JsonPath "$.value[*]".
- This gets JSON objects from "value" array and transforms them into SQL rows.

MORE INFORMATION:
- About "Get Groups" REST API endpoint:
  https://learn.microsoft.com/en-us/rest/api/power-bi/groups/get-groups
- About JsonPath used in "Filter" parameter:
  https://zappysys.com/blog/jsonpath-examples-expression-cheetsheet  
*/

Get __DynamicRequest__

SELECT * FROM __DynamicRequest__

generic_request endpoint belongs to __DynamicRequest__ table(s), and can therefore be used via those table(s).

Create SQL view in ODBC data source

ZappySys API Drivers support flexible Query language so you can override Default Properties you configured on Data Source such as URL, Body. This way you don't have to create multiple Data Sources if you like to read data from multiple EndPoints. However not every application support supplying custom SQL to driver so you can only select Table from list returned from driver.

If you're dealing with Microsoft Access and need to import data from an SQL query, it's important to note that Access doesn't allow direct import of SQL queries. Instead, you can create custom objects (Virtual Tables) to handle the import process.

Many applications like MS Access, Informatica Designer wont give you option to specify custom SQL when you import Objects. In such case Virtual Table is very useful. You can create many Virtual Tables on the same Data Source (e.g. If you have 50 URLs with slight variations you can create virtual tables with just URL as Parameter setting.

  1. Go to Custom Objects Tab and Click on Add button and Select Add Table:
    ZappySys Driver - Add Table

  2. Enter the desired Table name and click on OK:
    ZappySys Driver - Add Table Name

  3. And it will open the New Query Window Click on Cancel to close that window and go to Custom Objects Tab.

  4. Select the created table, Select Text Type AS SQL and write the your desired SQL Query and Save it and it will create the custom table in the ZappySys Driver:
    Here is an example SQL query for ZappySys Driver. You can insert Placeholders also. Read more about placeholders here

    SELECT
      "ShipCountry",
      "OrderID",
      "CustomerID",
      "EmployeeID",
      "OrderDate",
      "RequiredDate",
      "ShippedDate",
      "ShipVia",
      "Freight",
      "ShipName",
      "ShipAddress",
      "ShipCity",
      "ShipRegion",
      "ShipPostalCode"
    FROM "Orders"
    Where "ShipCountry"='USA'

    ZappySys Driver - Create Custom Table
  5. That's it now go to Preview Tab and Execute your custom virtual table query. In this example it will extract the orders for the USA Shipping Country only:

    SELECT * FROM "vt__usa_orders_only"
    ZappySys Driver - Execute Custom Virtual Table Query

Make generic REST API request in UiPath via SQL view

  1. Open UiPath Studio.

  2. Before we really begin the work, make sure UiPath Studio is set as your profile (blue application icon).

  3. In case, it is set to UiPath StudioX, you can change it in UiPath StudioX Settings:

    Choosing UiPath Studio profile

    Simply select UiPath Studio option:

    Choosing UiPath Studio profile
  4. Start by creating a new project based on UiPath Process template:

    Creating new process in UiPath Studio to import ODBC data
  5. Add Run Query activity in Main Sequence box:

    Adding ODBC data source in UiPath Studio
  6. Click Configure Connection... button to create an ODBC connection:

    Configuring ODBC data source in UiPath in Run Query activity
  7. Continue by clicking Connection Wizard:

    Using connection wizard to setup ODBC source in UiPath Studio
  8. When the window opens, select ODBC-based driver, provider, and then choose ODBC data source:

    PowerBiDSN
    PowerBiDSN
    Choosing ODBC DSN in UiPath Studio connection wizard
    You can also select Use connection string option and use whole ODBC connection string instead. Obtain the connection string by pressing Copy Settings button in your data source configuration.
  9. Once you do that, it's time to configure a SQL query:

    Inputting SQL query for ODBC data source in UiPath Studio
    Make sure, you enclose the query in double quotes!
  10. Proceed by adding a Write CSV activity after Run Query:

    Adding Write CSV activity to write ODBC data in UiPath
    In this article we are using Write CSV, but you can freely add any other destination of your choice, e.g. Write DataTable to Excel.
  11. Once you do that, configure the added Write CSV, this will write Power BI data to a CSV file:

    Configuring Write CSV activity to write ODBC data in UiPath
  12. It's time for fun! Which means it's time for debugging! Just run the package locally to debug:

    Running UiPath process package to get ODBC data
  13. Finally, ensure there are no execution errors!

    Successful UiPath package debugging

Advanced topics

Creating SQL stored procedures

You can create procedures to encapsulate custom logic and then only pass handful parameters rather than long SQL to execute your API call.

Steps to create Custom Stored Procedure in ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

  1. Go to Custom Objects Tab and Click on Add button and Select Add Procedure:
    ZappySys Driver - Add Stored Procedure

  2. Enter the desired Procedure name and click on OK:
    ZappySys Driver - Add Stored Procedure Name

  3. Select the created Stored Procedure and write the your desired stored procedure and Save it and it will create the custom stored procedure in the ZappySys Driver. Here is an example stored procedure for ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

    CREATE PROCEDURE [usp_get_orders]
        @fromdate = '<<yyyy-MM-dd,FUN_TODAY>>'
     AS
        SELECT * FROM Orders where OrderDate >= '<@fromdate>';
    
    ZappySys Driver - Create Custom Stored Procedure
  4. That's it now go to Preview Tab and Execute your Stored Procedure using Exec Command. In this example it will extract the orders from the date 1996-01-01:

    Exec usp_get_orders '1996-01-01';
    ZappySys Driver - Execute Custom Stored Procedure

Conclusion

And there you have it — a complete guide on how to make generic REST API request in UiPath without writing complex code. All of this was powered by Power BI ODBC Driver, which handled the REST API pagination and authentication for us automatically.

Download the trial now or ping us via chat if you have any questions or are looking for a specific feature (you can also reach out to us by submitting a ticket):

More actions supported by Power BI Connector

Got another use case in mind? We've documented the exact setups for a variety of essential Power BI operations directly in UiPath, so you can skip the trial and error. Find your next step-by-step guide below:

More Power BI integrations

All
Data Integration
Database
BI & Reporting
Productivity
Programming Languages
Automation & Scripting
ODBC applications