EDIS REPORTING USING POWERBI

Overview

The EDIS SYSTEM provides an API that allows data to be exported into SharePoint or PowerBI reports 

Pre-requisites

  1. A PC with windows Power BI desktop installed
  2.  Registered EDIS user credentials
  3. Internet connection to api.electricalcertificates.co.uk
  4. Note: Access to the reports is “read only”, so no updates are made via Power BI.
 
Open the Power BI file
  1.  Request a PowerBI file from su*****@***********************co.uk
 
Obtaining a Key:
  1. Select your User profile from the main menu (Top right hand side)
  2. Click on the Access Keys tab
  3. In the API Keys section – Click generate key 
  4. Click on the blue copy button to copy the key
 

Creating  connection and testing the connection:

  1. Open PowerBI Desktop
  2. Open the PowerBI file
  3. Go to Home tab > Transform data > Edit Parameters.
  4. Replace the placeholder value in the x_edis_api_key (and any other relevant parameters) with their actual key.
  5. Click Apply Changes (or Close & Apply) to reload the data using their credentials.

 

 === FOR ADVANCED USERS====

 

 Select Get Data option and then Blank query: 

 

– The blank Query allows you to add a script, past the script below into the advanced editor window:

 
edis_get_actions_required PowerQuery Script – The script below will return the actions required in a building, remember to change the username and password
 
let
    // Set the base URL
    baseUrl = “https://api.electricalcertificates.co.uk”,
    // Define API URLs as variables
    loginUrl = baseUrl & “/login”,
    actionRequiredUrl = baseUrl & “/actionrequired”,
 
    // First API Call: Get Login Token
    jsonPayload = Json.FromValue(
        [
            user_email = “yo**@***il.com“,
            user_password = “your_edis_password”
        ]
    ),
    response = Web.Contents(
        loginUrl,  // Use the login URL variable
        [
            Headers = [
                #”Content-Type” = “application/json”
            ],
            Content = jsonPayload
        ]
    ),
    jsonResponse = Json.Document(response),
    edis_login_token = if Record.HasFields(jsonResponse, “token”) 
                        then Record.Field(jsonResponse, “token”) 
                        else error “Token not found in response.”,
 
    // Second API Call: Use Token
    token_value = edis_login_token,
    jsonPayload2 = Json.FromValue(
        [
            token = token_value,
            filters = []
        ]
    ),
    response2 = Web.Contents(
        actionRequiredUrl,  // Use the action required URL variable
        [
            Headers = [
                #”Content-Type” = “application/json”
            ],
            Content = jsonPayload2
        ]
    ),
    jsonResponse2 = Json.Document(response2),
 
    // Extract the “action_required_items” list
    actionRequiredItems = if Record.HasFields(jsonResponse2, “action_required_items”) 
                          then jsonResponse2[action_required_items] 
                          else error “Field ‘action_required_items’ not found in response.”,
 
    // Convert the list to a table
    actionItemsTable = Table.FromList(actionRequiredItems, Splitter.SplitByNothing(), {“Record”}),
 
    // Expand the nested records into columns
    expandedTable = Table.ExpandRecordColumn(actionItemsTable, “Record”, 
        {“estate_name”, “building_name”, “observation_type”, “cert_number”, “cert_status”, 
         “item_no”, “board_circuit”, “observation_remedial_group”, “obs_org_group”, 
         “item_description”, “category_code”, “action_required”, “item_status”, 
         “comments”, “external_system_work_order_group”, 
         “external_system_work_order_reference”, “assigned_to”, “assigned_to_email”, “images”})
in
    expandedTabl