Preflight API

Set up API Credentials

Please watch this video for more details on authentication, token creation, and running a test using Preflight APIs.

Go to the Account Settings > API page to create or delete API keys. When viewing the API page you will see a form field for name. There will also be a link to the Preflight API documentation page which provides more information on API authentication among other API related actions.

To create your new API credentials just enter an informative name and then click the Create New API Key button. This will generate a Client ID and Client Secret that can be used to set up a request for example on Postman. You will have the ability to delete this API key if needed via the Delete API Key button located next to the key in question.

Examples

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 the 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

You can find your Test ID by going to your desired test's detail page and from the url:

For example:
https://app.preflight.com/tests/shO7PnuUAoV4/result
shO7PnuUAoV4 would be your test ID

CURL:

curl -X POST \
  https://api.preflight.com/v1/Tests/{TestId}/Run \
  -H 'content-type: application/json' \
  -H 'Authorization: bearer {TOKEN}' \
  --data '{}'

Javascript:

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

You can find your Group ID by going to your group page. The last part of the url of that page is your Group ID:

For example:
https://app.preflight.com/tests/groups/Sd98d13KAJSa
Sd98d13KAJSa would be your ID

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

You can also specify running all browsers, various screen sizes as well:

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}]})
});
Updated at Tue, Jan 24, 2023