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

Getting Started

This topic describes how to manage cloud phones by calling CPH APIs.

The token obtained from Identity and Access Management (IAM) is valid for only 24 hours. If you want to use a token for authentication, you can cache it to avoid frequently calling the IAM API.

Involved APIs

To use token authentication, you need to obtain a token and add X-Auth-Token to the request header of API calls.

  • API for obtaining tokens from IAM
  • API for querying the cloud phone list
  • API for restarting a cloud phone
  • API for querying the task list

Procedure

  1. Perform token authentication by following the steps provided in Authentication.
  2. Query the cloud phone list. Send GET https://{CPH Endpoint}/v1/{project_id}/cloud-phone/phones?offset=0&limit=100.
    1. Add X-Auth-Token to the request header.

      If the request succeeds, request_id and phones are returned.

      If the request fails, an error code and description are returned. For details, see Error Codes.

  3. Restart a cloud phone. Send POST https://{CPH Endpoint}/v1/{project_id}/cloud-phone/phones/batch-restart.
    1. Add X-Auth-Token to the request header.
    2. Specify the following parameters in the request body:
      {
          "phones": [
              {
                  "phone_id": "a7f3a1c5258347d6b6f1def79e11f2bc"
              }
          ]
      }

      If the request succeeds, request_id and jobs are returned.

      If the request fails, an error code and description are returned. For details, see Error Codes.

  1. Querying the task list. Send GET https://{CPH Endpoint}/v1/{project_id}/cloud-phone/ jobs?request_id={request_id}.
    1. Add X-Auth-Token to the request header.

      If the request succeeds, request_id and jobs are returned.

      {
          "request_id": "6a63a18b8bab40ffb71ebd9cb80d0085",
          "jobs": [
              {
                  "phone_id": "1234567b8bab40ffb711234cb80d0234",
                  "server_id": "1e223c8e-3ad0-4bf0-a837-bc90d4f91d01",
                  "node_id": "1e223c8e-3ad0-4bf0-a837-bc90d4f91d01",
                  "job_id": "1564567b8bab40f34711234cb80d0123",
                  "begin_time": "2017-10-25T00:00:00Z",
                  "end_time": "2017-12-26T00:00:00Z",
                  "status": 2,
                  "error_code": "", 
                  "error_msg": "" 
              },
      ......
          ]
      }

      If the request fails, an error code and description are returned. For details, see Error Codes.