Skip to content

Power BI

BotCity Insights offers the possibility to integrate Orchestrator data with the Power BI platform using API resources.

This way, you can continue using the features you are already familiar with along with the data reported to BotCity Insights.

Info

The intention of this guide is to demonstrate only a few simple examples that can be used in the context of Power BI.

For a more complete reference of the BotCity Insights API, visit this link.

Authentication

The first step to use the BotCity Insights API is authentication. The API uses an authentication token that is sent in the header of all requests.

To obtain the access token using Power BI resources, follow the steps below:

  • Access Power BI Desktop and create a new report.
  • In the Get Data menu, select the Blank Query option.
  • Open the newly created query with the Advanced Editor so that you can enter the code using Power Query M.

PowerBI - new report

The code that will be used in this step is very simple, a POST request to the API login route passing the login and key information in the request body.

Tip

The login and key information can be obtained on the Developer Environment page of your workspace in the Orchestrator.

() =>
    let
        // Login route
        url = "https://developers.botcity.dev/api/v2/workspace/login",
        headers = [#"Content-Type" = "application/json"],

        // Passing the workspace information in the body of the request (Dev. Environment)
        postdata = Json.FromValue(
            [
                login = "<WORKSPACE_LOGIN>",
                key = "<WORKSPACE_KEY>"
            ]
        ),
        // Getting the response
        response = Web.Contents(url, [Headers = headers, Content = postdata]),
        Data = Json.Document(response),

        access_token = Data[accessToken]
    in 
        // Returning the obtained access token
        access_token

When you execute this query, you will notice that an API access token will be returned.

API - Access Token

Done! With the function that returns the API access token, you can now use it as a parameter in the other requests to consume the report data.

Consuming report data

The following endpoints can be used to consume BotCity Insights report data:

BASE URL
https://developers.botcity.dev
Type Route Description
GET /api/v1/insights/tasks Lists the data related to executed tasks
GET /api/v1/insights/runners Lists the data related to workspace runners
GET /api/v1/insights/automation Lists the data related to automations

Still in the created report, follow the steps below to consume the data using the BotCity Insights API:

  • In the New Source menu, select the option to create a new query using the Web source this time.

  • In the opened window, check the Advanced option and enter the base URL of the BotCity Insights API. PowerBI - New Web Source

  • In the second field referring to the URL parts, enter the route you want to use to consume the data.

  • As mentioned earlier, all BotCity Insights API requests require a token and an organization to be sent in the request header.

  • In the HTTP request header parameters field, enter the token obtained in the authentication step and the organization related to your workspace.

  • At this point, you should have a structure similar to this: PowerBI - Web Source

Tip

The value of the organization parameter will be the same as the login field, which can be obtained on the Developer Environment page of your workspace in the Orchestrator.

When the request is executed, the API response will be displayed in the data source configuration window.

With the API response, you can now perform the necessary treatments to display the data as desired.

PowerBI - Web Source - Response

Using the API in an advanced way

Making Power BI requests dynamic

When creating the query in the above format, Power BI will automatically generate code using Power Query M, containing the information that was passed.

In the example above, the access token parameter was passed manually, but we could make a small change to make the authentication step more dynamic.

Editing the query with the Advanced Editor and including the change to use the function created to obtain the token, we would have something like this:

Power BI - Example

Tip

The function responsible for obtaining the access token created in the authentication step can be passed as a parameter in future requests.

With this treatment, the token will be generated dynamically whenever the query is updated.