Connect your data to Power BI
You can connect your Agritec data to Power BI Desktop. Once you've established the connection, you can refresh Power BI to reload the latest data from Agritec.
The sections below describe two ways to connect your data to Power BI Desktop:
- Using HTTP headers.
- Using Web API.
Warning
Use the method that works best for you; however, if you intend to share your Power BI Desktop report, keep in mind that the HTTP headers method stores your PAT key in the report.
In both cases, you will need a Personal Access Token (PAT). For more about managing PATs, see Connect external systems.
Use HTTP headers to connect your data
To connect your data using HTTP headers:
- Select Get Data button in Power BI.
- Select Web option.
- Select Advanced radio button.
- In URL parts box, type the service URL that you want to get. For example https://api.agritecsoft.com/extern/datamart/FactBreeding
- Type
Authorization
in Http Request Header box. - Type
Bearer {your PAT}
in the next box. - Click Ok.
- Make sure that Anonymous option is selected (option by default).
- Click Connect.
Use Web API to connect your data
To connect your data using Web API:
- Select Get Data > Blank Query.
- Select Advanced Editor.
- In the Advanced Editor, enter the following query:
let
Source = Csv.Document(Web.Contents("https://api.agritecsoft.com/extern/datamart/FactBreeding", [ApiKeyName= "api-key"]),[Delimiter="#(tab)", Encoding=65001, QuoteStyle=QuoteStyle.Csv]),
#"Promoted Headers" = Table.PromoteHeaders(Source)
in
#"Promoted Headers"
- In the query, replace the url
https://api.agritecsoft.com/extern/datamart/FactBreeding
with the appropriate url. - Select Done to display a preview of the Agritec data you're connecting to your Power BI Desktop report.
- If this is your first time connecting Agritec data to Power BI Desktop, you'll see a warning that your credentials are invalid. To provide your Agritec credentials in the form of an PAT, follow these steps: 1 In the warning message, select Edit Credentials to display the Access Web Content window.
- Select Web API.
- In the Key field, enter your PAT.
- Select Connect.
Note
The above dax example is for data in tsv format. For json format you will need to use a different code. Please see the Power BI documentation.
For example, farms are in json format, not tsv. In this case, the code would be:
let
json = Json.Document(Web.Contents("https://api.agritecsoft.com/extern/farms", [ApiKeyName="api-key"]))
in json
Potential error messages:
- A web API key can only be specified when a web API key name is provided: You need to include
ApiKeyName
in your request rather than building up Authorization yourself.
Web services
Agritec API exposes some services to get data for Power BI. The API root is https://api.agritecsoft.com. See Data Wareshouses