REST API

Get started with the Perfecto REST APIs, a RESTful web service that provides an interface for accessing Perfecto Lab functionality and data from a remote client over the web.

Note

If you are a Free Trial user, only the Repository Operations API is relevant for you.

API Operations

The following API operations are available:

Operatio

Description

Command

Legacy. Use Selenium instead.

Run a sequence of Perfecto automation commands.

Desktop Web

Query the Perfecto Lab for information related to desktop web devices and executions.

Device, Device Host & Cradle

Legacy but still relevant. Get info on one or all devices, device hosts, or cradles.

Group (old)

Legacy. Use the new group management APIs instead.

Create, update, list, and delete groups.

Group (new) Create and update groups, get group information, delete groups, and find groups.

License

Retrieve license information for all devices or by type (desktop or simulator devices).

Report

Legacy. Only relevant if you do not use the latest Perfecto UI for reporting.

Download reports, images, video, vitals & network information.

Repository (old)

Legacy. Use the new repository APIs instead.

Upload & download items, list, delete, and clean the repository.

Repository (new)

Upload, download, list, and delete items. Change the repository item locator. Get and edit item information.

Reservation

Legacy but still relevant. Reserve devices.

Role Add a user to a device group. Remove a user from a device group. Add roles to a user. Remove roles from a user.

Scheduler

Legacy. Only relevant for the old automation IDE.

Create, update, delete, and list scheduled scripts.

Script

Start script executions, get status, aborting, and listing.

User & Account

Legacy. Use the new user management APIs instead.

Create, update, list, and delete users

User Create, update, delete, and find users.

Authentication in new APIs

All new APIs (those not labeled as legacy) use the header Perfecto-Authorization, where the value is the Perfecto security token.

Information on legacy APIs

This section provides information on all APIs marked as legacy in the above table.

URL Structure

The following is the API URL request structure:

Copy
https://<hostName>/services/<resourceGroup>/<resourceIdentifier>?operation=<value>&<mandatoryParameter>=<value>&<optionalParameter>=<value>

where:

  • <hostName> is the ost name for the service. For example, mycloud.perfectomobile.com.

  • <resourceGroup> is a resource group. For example, executions.

  • <resourceIdentifier> is a resource identifier. This is only required if the API call is on a specific resource such as aborting a specific execution.

  • operation is the operation to perform. For example, abort.

  • <mandatoryParameters> are one or more required parameters specified using name-value pairs prefixed by the & character. For example, &offlineToken=securityToken.

  • <optional parameters> are one or more optional parameters specified using name-value pairs prefixed by the & character. For example, &responseFormat=XML.

Authentication & Authorization

It is required to send authentication in the form of the Perfecto security token. For more information, see Generate security tokens.

Copy
https://mycloud.perfectomobile.com/services/handsets?operation=list&securityToken=mySecurityToken&status=connected

Some operations require specific user permissions. For example, user operations require the administrator or user management role.

Protocols

The API request can be transmitted to the API server using either the GET or the POST HTTP methods. To use the GET method, simply specify the request as a URL. Parameter values must be encoded to prevent conflicts with HTTP special characters. The following example shows the URL for getting a list of all connected handsets in mycloud.

Copy
https://mycloud.perfectomobile.com/services/handsets?operation=list&securityToken=mySecurityToken&status=connected

You can get the same list using the POST method specifying the POST parameters as follows:

Copy
URL: https://mycloud.perfectomobile.com/services/handsets
Request: operation=list&securityToken=mySecurityToken&status=connected

Operations that upload files to the Perfecto repository must use POST or PUT method.

Response Formats

The default response format is JSON. Most operations support the optional parameter responseFormat for specifying the required format. A few operations support only XML response format.

  • JSON - For more information about the JSON format, see http://www.json.org.
  • XML - the response is an XML document.

The following examples show the response type for a request to start a new execution:

JSON
{
    "executionId" : "samb@perfectomobile.com_controller_16-11-03_08_32_32_4",
    "testGridReportUrl" : "https://mobileCloud.reporting-01.perfectomobile.com?externalId[0]=samb@perfectomobile.com_controller_16-11-03_08_32_32_4",
    "singleTestReportUrl" : "https://mobilecloud.perfectomobile.com/nexperience/singletest/report/?reportRepositoryKey=PRIVATE:controller/161103/controller_16-11-03_08_32_32_4.xml&ownerId=samb@perfectomobile.com&sharingCode=700d8374-776c-4147-8ae4-9cc1b11980ca",
    "reportKey" : "PRIVATE:controller/161103/controller_16-11-03_08_32_32_4.xml"}
Copy

XML

<response>
    <executionId>
        samb@perfectomobile.com_controller_16-11-03_08_39_41_5
    </executionId>    
    <testGridReportUrl>
        https://mobilecloud.reporting-01.perfectomobile.com?externalId[0]=samb@perfectomobile.com_controller_16-11-03_08_39_41_5
    </testGridReportUrl>
    <singleTestReportUrl>
        https://mobilecloud.perfectomobile.com/nexperience/singletest/report/?reportRepositoryKey=PRIVATE:controller/161103/controller_16-11-03_08_39_41_5.xml&ownerId=samb@perfectomobile.com&sharingCode=9aeaf95e-599f-4234-92b5-31e4627b765d
    </singleTestReportUrl>
    <reportKey>
        PRIVATE:controller/161103/controller_16-11-03_08_39_41_5.xml
    </reportKey>
</response>

Test Your API Access

  1. Open a web browser.
  2. Type the following in the address bar, substituting myCloud and securityToken as appropriate, and then press ENTER:

    Copy
    https://myCloud.perfectomobile.com/services/handsets?operation=list&securityToken=mySecurityToken
  3. Confirm that the API returns an XML list of devices.

Error Handling

Error messages returned in the response of an API operation are self-explanatory and should be sufficient to resolve issues, as can be seen from the following examples:

Copy
# Cause: The specified execution id could not be found
# Resolution: Verify that the executionId is correct
{"errorMessage":"Failed to get execution status - Execution executionId wasn't found"}
# Cause: The specified user does not have sufficient permission to perform the requested operation
# Resolution: If you want to use this operation, you can either use a user with the correct permissions or request the correct permission for this user
{"errorMessage":"Failed to get execution list - User username is not authorized to get all script executions"}
# Cause: The specified parameter is not valid for the abort operation
# Resolution: If the parameter is valid for this operation then report the issue, otherwise remove the parameter and try again
{"errorMessage":"Failed to abort script - Request contains unknown parameters: [time.offset]"}

The following table provides guidance for resolving some of the common HTTP codes that you may encounter:

Response Cause Resolution
400 Bad Request One or more of the specified parameters is not valid. Fix incorrect parameters in the URL.
401 Unauthorized Authentication is required and has failed. Fix incorrect authorization parameters in the URL.
500 Internal server error Internal server error. Contact your system administrator.

Common Errors For Invalid HTTP API URLs

Copy

JSON response

# Cause: Invoking the HTTP API without using HTTPS
# Resolution: Use HTTPS
{"errorMessage":"The operation requires secured channel"}
# Cause: Invoking the HTTP API with an unknown resource
# Resolution: Verify that the resource name is correct
{"errorMessage": "Could not find resource 'startexecutions'"}
# Cause: Invoking the HTTP API with an unknown operation
# Resolution: Verify that the operation name is correct
{"errorMessage": "Could not find operation 'executescript' for resource 'executions'"}
Copy

XML response

<!--Cause: Invoking the HTTP API with an unknown operation-->
<!--Resolution: Verify that the operation name is correct-->
<response>
    <errorMessage>Could not find operation 'executescript' for resource 'executions'</errorMessage>
</response>