Preflight API
This topic discusses authentication, token creation, and running tests using Preflight's APIs.
Setting up API Credentials
To Set Up API Credentials
-
In the Navigation bar, select your profile icon and navigate to Account Settings > API.
-
Enter an informative name in the Name field and click Create New API Key. This generates a Client ID and Client Secret that can be used to set up a request, for example on Postman. If required, delete this API key by clicking Delete API Key.
Use our CLI
We recommend using the CLI for simplicity and ease of use.
For details of available API commands, see npmjs.com/package/@applitools/preflight-cli
Rest Examples
This section provides a few examples to help you get started.
If you don't specify any options, the test will run with the default settings. See Optional Extras below for an example of how to specify browsers and screen sizes.
Get Token
CURL:
curl -X POST \
https://preflightauth.applitools.com/connect/token \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'client_id={YOUR_CLIENT_ID}&client_secret={YOUR_CLIENT_SECRET}&grant_type=client_credentials&scope=tests_run'
JavaScript:
fetch('https://preflightauth.applitools.com/connect/token',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: 'client_id={YOUR_CLIENT_ID}&client_secret={YOUR_CLIENT_SECRET}&grant_type=client_credentials&scope=tests_run'
});
Run a Single Test
To Run a Single Test
You can find a test's ID by going to its Test Details page and locating it in the URL:
For example:
https://preflight.applitools.com/tests/shO7PnuUAoV4/result
shO7PnuUAoV4 would be your test ID
CURL:
curl -X POST \
https://preflightapi.applitools.com/v1/Tests/{TestId}/Run \
-H 'content-type: application/json' \
-H 'Authorization: bearer {TOKEN}' \
--data '{}'
JavaScript:
fetch('https://preflightapi.applitools.com/v1/Tests/{TestId}/Run',
{
method: 'POST',
headers: {
'Authorization': 'bearer ' + {TOKEN},
'Content-Type': 'application/json'
},
body: JSON.stringify({})
});
Run a Group of Tests
To Run a Group of Tests
You can find a Group ID by going to the group's page. The last part of the url of that page is the Group ID:
For example:
https://preflight.applitools.com/tests/groups/Sd98d13KAJSa
Sd98d13KAJSa would be your ID
CURL:
curl -X POST \
https://preflightapi.applitools.com/v1/Tests/Run \
-H 'content-type: application/json' \
-H 'Authorization: bearer {TOKEN}' \
--data '{groupId:"Sd98d13KAJSa"}'
JavaScript:
fetch('https://preflightapi.applitools.com/v1/Tests/Run',
{
method: 'POST',
headers: {
'Authorization': 'bearer ' + {TOKEN},
'Content-Type': 'application/json'
},
body: JSON.stringify({groupId:"Sd98d13KAJSa"})
});
Run All Tests
To Run All Tests
CURL:
curl -X POST \
https://preflightapi.applitools.com/v1/Tests/Run \
-H 'content-type: application/json' \
-H 'Authorization: bearer {TOKEN}' \
--data '{}'
JavaScript:
fetch('https://preflightapi.applitools.com/v1/Tests/Run',
{
method: 'POST',
headers: {
'Authorization': 'bearer ' + {TOKEN},
'Content-Type': 'application/json'
},
body: JSON.stringify({})
});
Optional Extras
To Specify the Browsers and Screen Sizes
Specify the browsers and screen sizes as follows:
CURL:
curl -X POST \
https://preflightapi.applitools.com/v1/Tests/Run \
-H 'content-type: application/json' \
-H 'Authorization: bearer {TOKEN}' \
--data '{platforms:[{ 'platform': 'windows', 'browser': 'chrome' }], sizes: [{width: 1440, height: 900}]}'
JavaScript:
fetch('https://preflightapi.applitools.com/v1/Tests/Run',
{
method: 'POST',
headers: {
'Authorization': 'bearer ' + {TOKEN},
'Content-Type': 'application/json'
},
body: JSON.stringify({platforms:[{ 'platform': 'windows', 'browser': 'chrome' }], sizes: [{width: 1440, height: 900}]})
});
Related topics