BI Integration (Power BI)

You can connect Power BI directly to the Statistics API to build dashboards based on real-time usage data.


Example Power BI Dashboard

Below is an example of what a dashboard might look like:

Statistics Power BI Dashboard

This dashboard includes:

  • Total number of editor documents
  • Counts grouped by template and date
  • Document volume per hour

Integration Script (Power Query M)

(page as text) =>
let
    client_id = "your-client-id",
    client_secret = "your-client-secret",
    token_url = "https://identity.stage.metaforcelabs.com/connect/token",
    api_url = "https://api.statistics-v2.stage.metaforcelabs.com/analytics?pageSize=1000&pageNumber=" & page,
    scope = "api.external",
 
    GetAccessToken = () =>
        let
            Body = Text.ToBinary("grant_type=client_credentials" &
                "&client_id=" & client_id &
                "&client_secret=" & client_secret &
                "&scope=" & scope),
            TokenResponse = Json.Document(Web.Contents(token_url,
                [Content = Body, Headers = [#"Content-Type" = "application/x-www-form-urlencoded"]])),
            AccessToken = TokenResponse[access_token]
        in AccessToken,
 
    AccessAPI = (accessToken as text) =>
        let
            ApiResponse = Json.Document(Web.Contents(api_url,
                [Headers = [Authorization = "Bearer " & accessToken]])),
            Data = ApiResponse[data]
        in Data,
 
    token = GetAccessToken(),
    data = AccessAPI(token),
    Table1 = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Expanded = Table.ExpandRecordColumn(Table1, "Column1",
        {"event", "system", "date", "hour", "template", "source", "distribution", "environment", "area", "count"},
        {"event", "system", "date", "hour", "template", "source", "distribution", "environment", "area", "count"})
in Expanded

🔁 Use a loop to fetch multiple pages and build larger datasets.