Connect Power BI to the Data API
Power BI Desktop can call the Data API through Power Query. Start with a small result, verify the schema, and then expand the query.
Prerequisites
- Power BI Desktop on Windows
- A Corva API key with read access
- The target dataset and an accessible
asset_idorcompany_id
Create a blank query
- In Power BI Desktop, select Get data and then Blank query.
- Open Advanced Editor.
- Replace the editor contents with the query below.
- Replace
12345andYOUR_API_KEY.
let
Url = "https://data.corva.ai/api/v1/data/corva/metrics/",
Parameters = [
query = "{""asset_id"":12345}",
limit = "100",
sort = "{""timestamp"":-1}",
fields = "timestamp,asset_id,data.key,data.value"
],
Source = Json.Document(
Web.Contents(
Url,
[
Headers = [Authorization = "API YOUR_API_KEY"],
Query = Parameters
]
)
),
Results = Table.FromRecords(Source)
in
Results
Shape the result
- Convert the returned list to a table if Power BI has not already done so.
- Expand the
datarecord. - Assign appropriate data types to
timestampand metric values. - Rename the query to identify the dataset and filter.
- Refresh the preview before building visuals.
Keep the key out of the query
The inline placeholder is useful only for the first local test. For a maintained report, store the credential in an approved Power BI data-source or gateway configuration. Do not publish a report containing a real key in the query text.
Troubleshooting
| Symptom | Check |
|---|---|
401 Unauthorized | The header must use API followed by the current key. |
403 Forbidden | The key may not have access to the asset or dataset. |
| Empty table | Verify the asset ID, dataset, and filter. |
| Refresh is slow | Reduce the time range, limit, and returned fields. |
| Formula firewall error | Review Power BI privacy levels and gateway configuration. |
Use Filtering, Sorting, and Pagination to build additional query parameters.