> For the complete documentation index, see [llms.txt](https://docs.wirebootstrap.com/powerbi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wirebootstrap.com/powerbi/data-connector.md).

# Data Connector

The [Power BI REST API](https://docs.microsoft.com/en-us/rest/api/power-bi/) is a data service that allow applications to manage Power BI content, perform admin operations, and embed Power BI content inside custom applications.

The WireBootstrap for Power BI API Data Connector is a [WireBootstrap data connector](https://docs.wirebootstrap.com/wirebootstrap/connecting-to-data/data-connectors) that can talk to Power BI using the Power BI REST APIs.  The [WireBootstrap for Power BI REST API Data Connector](https://docs.wirebootstrap.com/powerbi/data-connector.md) allows lists of meta data such as dashboards and reports to be displayed inside WireBootstrap components other page elements with minimal configuration.

The data connector also serves data to WireBootstrap for Power BI embed components.

## Data Source

To use the data connector, create a [WireBootstrap data source](https://docs.wirebootstrap.com/wirebootstrap/connecting-to-data/data-sources) using the connector's service provider key in the initialization.  The service provider key for the WireBootstrap for Power BI REST API Data Connector is `pbi`.

```javascript
const source = new wire.data.DataSource("pbi", {
    ...
});
```

### Authentication

For security, the Power BI REST API requires an access token.  For details on creating a Power BI access token, visit [Access Tokens](https://docs.wirebootstrap.com/powerbi/access-tokens.md).

Once created, set the `Headers` configuration property when creating the data source to use the token with the `Bearer` authentication type as seen below.

```javascript
const authToken = "eyJ0e...Agjmg";

const source = new wire.data.DataSource("pbi", {
    Headers: { Authorization: "Bearer " + authToken },
    ...      
});
```

### Service Root

By default, the root URL of the Power BI REST API is located at the following location.

```
https://api.powerbi.com/v1.0/myorg
```

To specify a different location, use the `ServiceRoot` configuration property on the data source.

```javascript
const source = new wire.data.DataSource("pbi", {
    ServiceRoot: "https://some-other-address",
    ...
});
```

### Service Provider

Service provider specific properties are set on a WireBootstrap data source using the `Provider` property. &#x20;

The WireBootstrap for Power BI REST API Data Connector's service provider has one property called `groupId`.  This is the string id of the group or workspace containing the Power BI objects including dashboards and reports for which meta data will be retrieved using the data source.

The `groupId` value can seen in the browser's URL after opening a Power BI workspace.

```
https://app.powerbi.com/groups/{groupId}
```

```
https://app.powerbi.com/groups/efb178c2-31ec-4753-b4a6-98bbdf6d6300
```

To create a WireBootstrap data source against the workspace above, specify the `groupId` property on the `Provider` configuration object when creating the data source.

```javascript
const source = new wire.data.DataSource("pbi", {
    ...
    Provider: {
        groupId: "efb178c2-31ec-4753-b4a6-98bbdf6d6300"
    }
});
```

## Queries

Once created, a data source can execute queries against Power BI using the [standard table query interface in WireBootstrap](https://docs.wirebootstrap.com/wirebootstrap/creating-queries/select-queries).  The syntax for querying Power BI is below.

```javascript
const query = wire.data.select().from([entity])
    [.where().eq([entity], [id])]
```

For example, to request a list of dashboards, use the `dashboards` entity.

```javascript
const query = wire.data.select().from("dashboards");
```

To request a single dashboard, qualify the query using the dashboard's `id`.  A dashboard's id can be found in the browser's URL after opening the dashboard in Power BI.

```url
https://app.powerbi.com/groups/{groupId}/dashboards/{dashboardId}
```

```
https://app.powerbi.com/groups/efb178c2-31ec-4753-b4a6-98bbdf6d6300/dashboards/31f7bc8a-4a63-4ddb-86fb-84ced3ac8836
```

The query below requests details for the dashboard above.

```javascript
const query = wire.data.select().from("dashboards")
    .where().eq("dashboards", "31f7bc8a-4a63-4ddb-86fb-84ced3ac8836");
```

### Execute Queries

After creating a query, execute the query in Power BI using the `execAsync` method on the data source.

```javascript
const dashboards = await source.execAsync(query);
```
