Help Center> Cloud Phone Host> API Reference> Cloud Phone Server APIs> ADB Commands> Running the Synchronous ADB shell Commands
Updated on 2023-03-16 GMT+08:00

Running the Synchronous ADB shell Commands

Function Description

  • API name

    RunSyncCommand

  • Function

    This API is only used to synchronously execute ADB shell commands and return the command execution output on a cloud phone. Within one minute, you can call this API for up to 6 times. The timeout interval for a cloud phone to run a command is 2 seconds, and the API calling time does not exceed 30 seconds (excluding the 2-minute timeout interval). A larger number of cloud phones indicates a longer API calling time in total.

URI

POST /v1/{project_id}/cloud-phone/phones/sync-commands

Table 1 lists the URI parameter.
Table 1 URI parameter

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

For details about how to obtain the project ID, see Obtaining a Project ID.

Request

  • Request parameters

    Parameter

    Mandatory

    Type

    Description

    command

    Yes

    String

    Only shell is supported.

    content

    Yes

    String

    Specifies the command to be executed.

    The value can contain a maximum of 1,024 bytes, including only letters, digits, underscores (_), periods (.), slashes (/), colons (:), and hyphens (-).

    server_ids

    No

    Array of strings

    Specifies IDs of the cloud phone servers.

    This parameter is mandatory when phone_ids does not need to be configured.

    Obtain them by referring to Querying Cloud Phone Servers.

    phone_ids

    No

    Array of strings

    Specifies cloud phone IDs.

    This parameter is mandatory when server_ids does not need to be configured.

    Obtain them by referring to Querying Cloud Phones.

  • Example request
    POST https://{CPH Endpoint}/v1/{project_id}/cloud-phone/phones/sync-commands
    {
        "command": "shell",
        "content": "ls -l /system",
        "phone_ids": [
            "1234567b8bab40ffb711234cb80d0234",
            "1678567b8bab40f93711234cb80d0764"
        ]
    }

Response

  • Response parameters

    Parameter

    Type

    Description

    request_id

    String

    Specifies the unique request ID.

    jobs

    Array of objects

    Specifies the job information. For details, see Table 2.

    Table 2 Data structure description of job

    Parameter

    Type

    Description

    phone_id

    String

    Specifies the unique ID of a cloud phone. This parameter is contained in jobs related to cloud phones.

    job_id

    String

    Specifies the unique ID of a job.

    status

    Integer

    Specifies the job status.

    • 2: The job succeeded.
    • -1: The job failed.

    error_code

    String

    Specifies the error code of the job.

    error_msg

    String

    Specifies the error message of the job.

    execute_msg

    String

    Specifies the content returned after a job is executed. The value can contain a maximum of 1,024 bytes. The command output is returned regardless of whether the command is successfully executed.

  • Example response
    {
        "request_id": "6837531fd3f54550927b930180a706bf",
        "jobs": [{
            "phone_id": "1234567b8bab40ffb711234cb80d0234",
            "job_id": "3fc17538866a4ff3a014d8bc6aaa4b69",
            "status": -1,
            "error_code": "CPS.0191", 
            "error_msg": "Run command failed.",
            "execute_msg": "ls: cannot access '/system': No such file or directory" 
        },
        {
            "phone_id": "1678567b8bab40f93711234cb80d0764",
            "job_id": "1564567b8bab40f34711234cb80d5678",
            "status": 2,
            "error_code": "", 
            "error_msg": "",
            "execute_msg": "xxxxx"
        }]
    }

Returned Values

See Returned Values.

Error Codes

See Error Codes.