fbpx

Using Akixi API with PowerShell

Akixi is a great reporting platform for the Horizon VOIP telephony platform. Recently i’ve been working on pulling off report data and inserting that data into our central dashboard systems.

They don’t provide code examples in PowerShell so I wanted to share the basics so you can get a head start with your own project. All I ask is that you post a comment below and share your project details with other readers 🙂

First up you will need to create a new account on the Akixi platform and tick the API box to enable API access for the user.

Grab the code below, enter your username and password and run the script. The code will first login then list all available reports along with their ID’s.

Grab the ID for a report you wish to run then update the script again to pass into the execute report code.

Executing a report can take some time so it first requests the report and then loops until the report has a status of ACTIVE. Once the state changes to ACTIVE the contents of the report are collected.

You can see below the report body contains an array ‘rows’ and its in there that you will find the data for your executed report.

Now you can access the report data you can do whatever you need with it. Export it to a CSV file, insert it into a database or sent it to another system using its own API.

I hope you find this quick start guide helpful!

Download the code here:

Akixi API (10 downloads)
###########################################################
#
# Author: Ian Waters @ SlashAdmin / Life in IT
#
# API Developer Page Page https://akixi.dev/
#
###########################################################


Clear-Host


#Encode Login Credentials (Remember to Tick the API checkbox on the account used in the Akixi portal)
$user = "enter username here"
$pass = "enter password here"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$pass)))

#Get Session
Write-Host "Getting Session" -ForegroundColor Green
$url = "https://horizon.akixi.com/CCS/API/v1/session"
$response = Invoke-RestMethod -uri $url -Method Post -SessionVariable se
Write-Host "Get Session Response: " $response


#Authentication
Write-Host "Authenticating" -ForegroundColor Green
$headers = @{
    'Authorization' = "Basic $base64AuthInfo"
}
Write-Host "Using Headers:" -ForegroundColor Green
$headers
$url = "https://horizon.akixi.com/CCS/API/v1/login?locale=en_GB"
$response = Invoke-RestMethod -uri $url -Headers $headers -Method Get -WebSession $se
Write-Host "Authentication Response: " $response


#List Reports
Write-Host "Listing Reports" -ForegroundColor Green
$url = "https://horizon.akixi.com/CCS/API/v1/report"
$response = Invoke-RestMethod -uri $url -Method Get -WebSession $se
$response


#Exe Report
Write-Host "Executing Report" -ForegroundColor Green
#Enter your own report id below to execute it
$reportID = "b4ed0dfe61a0bea4:d956b4c:1753193f226:5ccd"
$url = "https://horizon.akixi.com/CCS/API/v1/report/$($reportID)/exec"

do
{
    $response = Invoke-RestMethod -uri $url -Method Get -WebSession $se
    Start-Sleep -Seconds 2
}
while($response.ExecutionStatus -eq "WAITING")

if($response.ExecutionStatus -eq "ACTIVE")
{
    Write-Host "Report is ready" -ForegroundColor Green
    $response

    Write-Host "Report Row Output" -ForegroundColor Green
    foreach($row in $response.Body.Rows)
    {
        $row
    }
}
else
{
    Write-Host "Possible issue, execution status:" $response.ExecutionStatus 
}


#Logout
Write-Host "Logging out" -ForegroundColor Green
$url = "https://horizon.akixi.com/CCS/API/v1/logout"
$response = Invoke-RestMethod -uri $url -Method Get -WebSession $se


Author: Ian@SlashAdmin

Share This Post On
468 ad

Submit a Comment

Your email address will not be published. Required fields are marked *