Connect the HR API to Power BI
This topic explains one method to connect the HR API to Power BI.
Launch Power BI
-
Open the Power BI application.
The main interface opens.
Choose Blank report
-
Go to the menu and select Blank report.
-
In the Get Data section, select Blank Query.
You can also enter Blank Query into the search bar to quickly find it.
Access power query editor
-
Select Advanced Editor.
-
Copy and paste this code into the Advanced Editor:
Copylet
// First, get the access token
tokenUrl = "https://api.iris.co.uk/oauth2/v1/token ",
tokenHeaders = [
#"Content-Type" = "application/x-www-form-urlencoded",
#"Authorization" = "Basic {Your Access Key}"
],
tokenBody = "grant_type=client_credentials",
// Function to HTTP POST request for token
GetJsonToken = (url as text, body as text, headers as record) as record =>
let
response = Web.Contents(url, [
Headers = headers,
Content = Text.ToBinary(body)
]),
json = Json.Document(response)
in
json,
// Call the function and retrieve the token data
tokenResult = GetJsonToken(tokenUrl, tokenBody, tokenHeaders),
access = tokenResult[access_token],
// Then, use the access token to get employee data
employeeUrl = "https://api.iris.co.uk/hr/v2/employees",
employeeHeaders = [
#"Accept" = "application/json;odata.metadata=minimal;odata=true;version1",
#"Authorization" = "Bearer " & access
],
// Function to handle the HTTP GET request for employees
GetEmployeeData = (url as text, headers as record) as any =>
let
response = Web.Contents(url, [
Headers = headers
]),
json = Json.Document(response)
in
json,
// Call the function and retrieve the employee data
employeeResult = GetEmployeeData(employeeUrl, employeeHeaders)
in
employeeResult -
This code will:
-
Generate an access token (ensure you have entered your access key).
-
Call the employee endpoint and retrieve a list of employees.
-
-
After pasting the code into the editor, select Done.
-
If a data privacy error message appears, select Continue.
-
Select the appropriate security level.
Learn more about security levels.
You can now query the data using Power BI.