All Products
Search
Document Center

:Call API operations by using CLI

Last Updated:Mar 01, 2024

Cloud Shell is integrated with OpenAPI Explorer. Cloud Shell is a web-based CLI provided by Alibaba Cloud CLI. You can use Cloud Shell without the need to install it or specify an AccessKey pair.

Alibaba Cloud provides RPC and RESTful APIs. Most cloud services provide the RPC API, for example, Elastic Compute Service (ECS), ApsaraDB RDS, and Server Load Balancer (SLB).

The request method varies based on the architectural style of the API that you want to call. You can determine the API type based on the following descriptions:

  • If an API requires the Action parameter, it is an RPC API. If an API requires the PathPattern parameter, it is a RESTful API.

  • In general, all APIs in a cloud service are of the same type.

Start Cloud Shell

  1. Log on to OpenAPI Explorer.

  2. In the top navigation bar, click Select a cloud service. In the panel that appears, select the target cloud service.

  3. In the top navigation bar of the homepage of the cloud service, click API Debugging. On the page that appears, click the CLI Example tab.

  4. On the CLI Example tab, click the image.png icon to start Cloud Shell.

    You can also directly go to the page of Alibaba Cloud Shell.

Call an RPC API operation in Cloud Shell

You must comply with the following command format when you call an RPC API operation in Cloud Shell:

aliyun <ProductCode> <ActionName> [--parameter1 value1 --parameter2 value2]

Parameter

Description

Example

ProductCode

The cloud product code. For example, the product code for Elastic Compute Service (ECS) is ecs, and the service code for Server Load Balancer (SLB) is slb.

You can execute the aliyun --help command to view product codes.

Run the following command in Cloud Shell to view the configurations of an ECS instance.

Note

Replace i-bp198exxxxxx with the ID of the ECS instance.

aliyun ecs DescribeInstanceAttribute --InstanceId i-bp198exxxxxx | jq 

ActionName

The API operation that you want to call. For example, you can call the DescribeInstanceAttribute operation of ECS to view the details of an ECS instance.

parameter

The request parameters. For more information, see the API references of each Alibaba Cloud service.

Call a RESTful API operation in Cloud Shell

RESTful API applies to specific Alibaba Cloud services such as Container Service for Kubernetes (ACK). RESTful API operations are called in a way different from RPC API operations. The following section provides the formats of commands that are required to call RESTful API operations in Cloud Shell.

  • GET request

    aliyun <ProductCode> GET /<Resource>

    Example

    aliyun cs GET /clusters
  • POST request

    aliyun <ProductCode> POST /<Resource> --body "$(cat input.json)"

    Example

    aliyun cs POST /clusters/<cluster-id> --header "Content-Type=application/json" --body "$(cat attach.json)"
  • DELETE request

    aliyun <ProductCode> DELETE /<Resource>

    Example

    aliyun cs DELETE /clusters/<cluster-id>