A PowerShell API example

My first time working with this API. What got me is this is not RESTful. I hope the following PowerShell script may help others who, like me, are not proper developers. Failing that it will serve as a reminder for me.

########################################################################
### Modify according to your account application and method.
$AccountNumber = ""
$ApplicationID = ""
$Api_Key = ""
$Endpoint = "https://api.quickfile.co.uk/1_2/system/getaccountdetails"

########################################################################

$SubmissionNumber = [guid]::NewGuid().guid

$Creds = $AccountNumber + $Api_Key + $SubmissionNumber

$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$utf8 = New-Object -TypeName System.Text.UTF8Encoding
$Hash = (([System.BitConverter]::ToString($md5.ComputeHash($utf8.GetBytes($Creds)))).replace("-","")).tolower()

$Payload = [ordered]@{
    "payload" = @{
        "Header" = @{
            "MessageType" = "Request"
            "SubmissionNumber" = $SubmissionNumber
            "Authentication" = @{
                "AccNumber" = $AccountNumber
                "MD5Value" = $Hash
                "ApplicationID" = $ApplicationID
            }
        }
        # Modify according to your method. See QuickFile documentation
        "Body" = @{
            "@xmlns" = "https://api.quickfile.co.uk"
            "AccountDetails" = @{
                "AccountNumber" = $AccountNumber
                "ReturnVariables" = @{
                    "Variable" = @("CompanyName","CompanyNumber","Tel","VatRegNumber") #Add further attributes
                }
            }
        }
    }
}

$jsonPayload = $Payload| ConvertTo-Json -Depth 5

$Request = Invoke-WebRequest -Uri $Endpoint -Method Post -Body $jsonPayload
$oData = $Request.Content | ConvertFrom-Json
$oData.System_GetAccountDetails.Body.AccountDetails

$oData.System_GetAccountDetails.Body.AccountDetails.Tel

For further details, see the script on GitHub: https://github.com/arcotek-ltd/quickfile_api

HTH

1 Like

Thanks for sharing @woter324! :slight_smile:

Well done we have done a c# .net library as well

Thanks for sharing. I’ve found that Microsoft Flow also neatly integrates with the API.