Using the REST API with Eggplant Manager

Most of the actions that you can perform in the Eggplant Manager user interface (UI) can also be automated by using the REST API. This ability could be useful if you want to automate the process of running tests or generating user data reports. For example, you could use the REST API to integrate Eggplant Manager into a continuous integration (CI) environment. There are many REST API methods available.

The example on this page shows how to create a test, add a script to the test, execute the test, and check the status of the test run.

Authorization

The REST API uses HTTP basic authorization. You can use Eggplant Automation Cloud or Eggplant Manager user credentials, or the API token found at Account > Account Settings in Eggplant Manager. When using the API access token instead of username and password, replace the username with the token, and the password should be randomly generated (or blank).

API Access Token in Eggplant Manager Account Settings page

The API Access Token on the Eggplant Manager Account Settings page.

Note that the API Access Token field is hidden by default. To view this field, click the Show button. When the API Access Token field is visible, the Show button changes to a Reset button. If you click the Reset button, Eggplant Manager revokes the previous access token, then generates and displays a new token.

To use basic authorization, use this syntax:

http://<username>:<password>@<hostname>:<port>/<api_endpoint>

You can also use the token in place of the username and password, as shown below:

http://<token>@<hostname>:<port>/<api_endpoint>

If you're using cURL to run the API using the examples in the documentation, the access token must be base64 encoded. If you use Eggplant Functional, this script generates the access token in the appropriate format. Replace <token_string> in the script below with your API access token.

set mytoken to"<token_string>"

put base64encode(mytoken & ":")

The following script is an example of base64 encoding the username and password:

set username to "<username>"

set password to "<password>"

put base64encode(username & ":" & password)

Create a Test

To create a test:

http://<hostname>:<port>/api/test/create

Use these headers:

Content-Type: "application/json"

The request body is a JSON-encoded version of the following. The name is required.

{

name: "<name>",

description: "<description>",

...

}

This returns a JSON object:

{

...,

_id: "<test id>",

name: "<test name>",

...

}

Create a Test Execution

A Test execution is what is referred to as a script in the GUI. One or more test executions must be added to a test before a test can be executed. To create a test execution:

http://<hostname>:<port>/api/test_execution/create

Use these headers:

Content-Type: "application/json"

The request body is a JSON-encoded version of the following. The script path is required.

Note: You can use _id from the test created in Create a Test, above, to add this test execution (script) to that test. To get the _id of an existing test, see How to Generate a Custom URL for a Test. The _id follows the word test in the URL.

{

...,

test_id: "<test id>",

script_path: "<path to script>",

...

}

This returns a JSON object:

{

...,

_id: "<test execution id>",

script_path: "<script path>",

...

}

Note: To add an additional test execution (script) to a test, another test execution must be created with a path to the script and then added to the test by using the same test_id.

Execute a Test

To execute a test, send a GET request:

http://<hostname>:<port>/api/test/<test_id>/execute

This returns a JSON object:

{

"_id": "<test_run id>",

"test_run_number": <test run number>,

"test_id": "<test id>",

...

}

Check Test Run Status

Use the test run id from the previous execute request to check the test run status. Send a GET request:

http://<hostname>:<port>/api/test_run/<test_run_id>

This returns a JSON object:

{

"_id": "<test run id>",

"test_id": "<test id>",

"status_code": "<status code>",

"test_run_instances": [

{

"_id": "<test run instance id>"

}

],

"test_cases": [

{

"_id": "<test case id>",

"duration": 4.197,

"error_count": 0,

"exceptions": 0,

...

},

...

}

]

}

 

This topic was last updated on August 19, 2021, at 03:30:51 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant