Running Tests from a Script using REST API

There are many use cases where you want to start a test from a script. A common scenario is a regular execution from a server cron job or within a CI/CD build pipeline.

The first thing you need is your personal API-key. In the testup.io App (https://app.testup.io) you will find the API Key under the tab “Profiles”:

Now you can use the following APIs in a shell, for example:

Run a test.

curl -X POST "https://app.testup.io/api/v1/project/run-all/<Project ID>?testIds=<Test Case ID>"     
         -H "accept: */*" 
         -H "Content-Type: application/json"              
         -H "Authorization: ApiKey-v1 <APIKEY>"              
         -d "{\"message\":\"New run by curl\",\"threads\":1}"

where 

<APIKEY> is your API-key (see above),
<Project ID>  is the Project ID of your test (see URL of your project, e.g. 6607334),
<Test Case ID>  is the Test Case ID of your test (see URL of your test).
"New run by curl\" is the name of the new execution the command will create. You can change this freely.
"threads\" is the number of parallel test executions. 

This curl returns a JSON with the execution id <id>. Using this <id> you can get the status of the results:

curl -X GET "https://app.testup.io/api/v1/execution/<id>/details"              
     -H "accept: */*"              
     -H "Authorization: ApiKey-v1 <APIKEY>"

If you want to run all test cases at once, you can use

curl -X POST "https://app.testup.io/api/v1/project/run-all/<Project ID>"                
     -H "accept: */*" 
     -H "Content-Type: application/json"                
     -H "Authorization: ApiKey-v1 <APIKEY>"                
     -d "{\"message\":\"New run by curl\",\"threads\":2}"

Another feature you can use is to replace values in the test with new values using textMap. Or to change the url using urlMap:

PROJECTID=<Project ID>
CONFIG='{
    "message":"Run by Curl",
    "textMap":[{
       "old":"Beanie",
       "new":"Weenie"
    }],
    "urlMap":[{
       "old":"https://does-not-match",
       "new":"https://new-url"
    }]
}'
echo $CONFIG
curl -X POST https://app.testup.io/api/v1/project/run-all/$PROJECTID \   
     -H "accept: */*" \
     -H 'Content-Type: application/json' \
     -H "Authorization: ApiKey-v1 <APIKEY>" \
     -d "$CONFIG"