You can find our API documentation at api.preflight.com. However we wanted to provide a few simple examples to help you get started.
If you don't specify any options, it will run the test with it's default settings. See at the bottom an example which shows how to specify the environment, browsers and screen sizes.
Get Token
CURL:
curl -X POST \
https://auth.preflight.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://auth.preflight.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 via the API
CURL:
curl -X POST \
https://api.preflight.com/v1/Tests/{TestId}/Run \
-H 'content-type: application/json' \
-H 'Authorization: bearer {TOKEN}' \
--data '{}'
Javascript:
Run a single test via the API - JS
fetch('https://api.preflight.com/v1/Tests/{TestId}/Run',
{
method: 'POST',
headers: {
'Authorization': 'bearer ' + {TOKEN},
'Content-Type': 'application/json'
},
body: JSON.stringify({})
})
Run a Group of Tests
CURL:
curl -X POST \
https://api.preflight.com/v1/Tests/Run \
-H 'content-type: application/json' \
-H 'Authorization: bearer {TOKEN}' \
--data '{groupId:"Sd98d13KAJSa"}'
Javascript:
fetch('https://api.preflight.com/v1/Tests/Run',
{
method: 'POST',
headers: {
'Authorization': 'bearer ' + {TOKEN},
'Content-Type': 'application/json'
},
body: JSON.stringify({groupId:"Sd98d13KAJSa"})
})
Run All Tests
CURL:
curl -X POST \
https://api.preflight.com/v1/Tests/Run \
-H 'content-type: application/json' \
-H 'Authorization: bearer {TOKEN}' \
--data '{}'
Javascript:
fetch('https://api.preflight.com/v1/Tests/Run',
{
method: 'POST',
headers: {
'Authorization': 'bearer ' + {TOKEN},
'Content-Type': 'application/json'
},
body: JSON.stringify({})
})
Optional Extras
Of course, sometimes it's good to get away from the status quo. Here you'll see you can specify running all browsers, various screen sizes
CURL:
curl -X POST \
https://api.preflight.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://api.preflight.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}]})
})