Public API: Example start of test

Overview

Script example

Attachments

Overview

To get a more practical understanding of the start-test API call, you can use a PowerShell script demonstrating the call. The script file can be found under the Attachments. It's also downloadable from the Appliance. Once you have created a Test, you can download the script at the top of the window by clicking Test automation info.

mceclip0.png

After this, you will see a window with two links:

  • One for the Public API of your Appliance.
  • Another is for downloading the example PowerShell (.ps1) file.

mceclip1.png

Note that when you download the script from your own Appliance, it will be pre-configured for your environment and Virtual Appliance.

If you download it from the Attachments, you will need to configure the following three values:

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

# Test id
$testId = '3a9f24a1-232f-4849-8a37-56117ba82734'
  • $accessToken: Identifies the API token you generate to gain access. This needs to be a Schedule permission or higher.
  • $baseUrl: Denotes the URL of your Virtual Appliance.
  • $testId: Represents the GUID of your Test
    • You can find it in the URL bar of your browser after opening an environment.

mceclip2.png

Once you have configured these values, you can execute the Test. If everything is set up correctly, you should see "Success" as the return value.

mceclip0.png

Script example

You can download example scripts for each use case by clicking the green exclamation mark button mentioned earlier. This article uses the Continuous Test script as an 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}/v6/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 }
}
}

Attachments