Connect the HR API to Power BI

This topic explains one method to connect the HR API to Power BI.

Launch Power BI

  1. Open the Power BI application.

    The main interface opens.

    Choose Blank report

  2. Go to the menu and select Blank report.

    The Blank report option.

  3. In the Get Data section, select Blank Query.

    You can also enter Blank Query into the search bar to quickly find it.

    The Blank Query option.

Access power query editor

  1. Select Advanced Editor.

    The Advanced Editor.

  2. Copy and paste this code into the Advanced Editor:

    Copy
    let
    // 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
  3. This code will:

    • Generate an access token (ensure you have entered your access key).

    • Call the employee endpoint and retrieve a list of employees.

    The code pasted into the editor.

  4. After pasting the code into the editor, select Done.

  5. If a data privacy error message appears, select Continue.

    The data privacy error message.

  6. Select the appropriate security level.

    Learn more about security levels.

    You can now query the data using Power BI.