Public API: Example start of test

To give a more practical example of the start test API call we have created an example powershell script that is part of every Login Enterprise release from 4.1 and higher, in 4.3 and higher we have added an example script for each different use-case (Continuous, Load and Application testing). When you have created an Application Testing test scenario you can find this information at the top of the window.


Once clicked on the button you are shown a window that has two links, one is the link to the public API of your appliance and the other is linked to a download of the example PS1 file. If you do not have access to a Login Enterprise appliance you can view the Public API here and can download the PS1 file attached in this article, download is at the bottom of the article.


When the script is downloaded from your own appliance it will be pre-configured for the environment and Login Enterprise appliance. If you download it from our article you need to configure the following three(3) values:

[string]$accessToken = "U49-UKj5rtzP5cuL-PcsQsAQxtbGhwVT3OZesdLlUAE" 
[string]$baseUrl = 'https://MyLoginEnterpriseApplianceURL/publicApi'

# Test id
$testId = '3a9f24a1-232f-4849-8a37-56117ba82734'

The "$accessToken" is the API token you can generate yourself to gain access. This action needs the Schedule or higher permission. To create a token you can read this article. 

The "$baseUrl" is the URL your own Login Enterprise appliance on which you connect to. 

The "$testId" is the GUID of your test, this can be fetched when you have opened an environment from the URL bar of your browser.


Once done you can execute the test, if configured correctly you should see "Success" as a return value.


Example Script

This example script can be downloaded from each different use case by clicking on the green exclamation mark button as mentioned in the beginning of the article. This article uses the Continuous test script as example.

# basic information
# The access-token needs to be a System Access Token with the appropriate access
# For more information see https://MyLoginEnterpriseAppliance/external-notifications/public-api
[string]$accessToken = "U49-UKj5rtzP5cuL-PcsQsAQxtbGhwVT3OZesdLlUAE"
[string]$baseUrl = 'MyLoginEnterpriseAppliance/publicApi'

# Test id
$testId = '3a9f24a1-232f-4849-8a37-56117ba82734'
# Start-request data
$requestObject = @{
# Comment
'comment' = '...'

# if something goes wrong we stop processing this script
$ErrorActionPreference = 'Stop'

# this is only required for older version of PowerShell/.NET
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls11

# WARNING: ignoring SSL/TLS certificate errors is a security risk
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true; }

# set the content-type and add the authorization http header with our access token
$requestHeaders = @{
'Content-Type' = 'application/json'
'Authorization' = "Bearer $accessToken"

$requestBody = ConvertTo-Json -InputObject $requestObject
try {
$response = Invoke-RestMethod -Method Put -Uri "${baseUrl}/v4/tests/${testId}/start" -Headers $requestHeaders -Body $requestBody
Write-Host -Object 'Success'

catch {
[int]$statusCode = $_.Exception.Response.StatusCode;

switch ($statusCode) {
404 { Write-Host -Object 'Not Found' }
409 { Write-Host -Object 'Conflict' }
400 { Write-Host -Object 'Bad Request' }
401 { Write-Host -Object 'Unauthorized' }
default { throw }