Updated on 2024-08-09 GMT+08:00

Running adb Commands Synchronously

Function

This API is only used to synchronously run ADB shell commands and return the command 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-second 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 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the user token. It can be obtained by calling an Identity and Access Management (IAM) API. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

command

Yes

String

Specifies the ADB command. The value is fixed at shell.

content

Yes

String

Specifies the command to be executed.

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

phone_ids

No

Array of strings

Specifies the ID list of cloud phones. This parameter is mandatory when there is no parameter server_ids. If there is parameter server_ids, set phone_ids only.

server_ids

No

Array of strings

Specifies the ID list of cloud phone servers. This parameter is mandatory when there is no parameter phone_ids. If there is parameter phone_ids, set phone_ids only.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the unique request ID.

jobs

Array of RunSyncCommandJob objects

Specifies the task list.

Table 5 RunSyncCommandJob

Parameter

Type

Description

phone_id

String

Unique ID of a cloud phone. This parameter is contained in tasks related to cloud phones.

job_id

String

Specifies the unique ID of a task.

status

Integer

Specifies the task status.

  • 2: successful

  • 1: running

  • -1: failed

error_code

String

Task error code.

error_msg

String

Specifies the error message returned for the task.

execute_msg

String

Specifies the content returned after a task is executed. The value can contain a maximum of 1,024 bytes.

Example Requests

Running the ls -l /system command synchronously on cloud phones listed in phone_ids

POST https://{CPH Endpoint}/v1/{project_id}/cloud-phone/phones/sync-commands

{
  "command" : "shell",
  "content" : "ls -l /system",
  "phone_ids" : [ "1234567b8bab40ffb711234cb80d0234", "1678567b8bab40f93711234cb80d0764" ]
}

Example Responses

Status code: 200

OK

{
  "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"
  } ]
}

Status Codes

Status Code

Description

200

OK

Error Codes

See Error Codes.