Call APIs from the command line
OpenAPI Explorer provides the built-in Cloud Shell. Built on the Alibaba Cloud CLI, Cloud Shell is a web-based command-line interface (CLI) tool that requires no installation or AccessKey configuration and can be used immediately after you log on.
Alibaba Cloud APIs are either RPC or RESTful. Most products (ECS, ApsaraDB RDS, load balancer) use RPC APIs.
Identify the API type by these characteristics:
-
RPC APIs include an Action parameter, while RESTful APIs require a PathPattern parameter.
-
Typically, all API operations for a single cloud product are of the same type.
Start Cloud Shell
-
Log on to OpenAPI Explorer.
-
In the top navigation bar, click Select Cloud Product and select a cloud product from the panel.
-
Navigate to the product homepage. In the top navigation bar, click API debugging and select the CLI Example tab.
-
On the CLI Example tab, click the Cloud Shell icon
to start Cloud Shell.Alternatively, you can access Alibaba Cloud Shell directly.
Call RPC APIs in Cloud Shell
To call an RPC API in Cloud Shell, use the following format:
aliyun <ProductCode> <ActionName> [--parameter1 value1 --parameter2 value2]
|
Parameter |
Description |
Example |
|
|
The code of the cloud product to call. For example, the product code for Elastic Compute Service is Run the |
Execute the following command in Cloud Shell to view the configuration information of a specific ECS instance. Note
Before you run the command, replace the instance ID.
|
|
|
The API to call. For example, use the |
|
|
|
The request parameters to pass. For more information, see the API documentation for each cloud product. |
Call RESTful APIs in Cloud Shell
Some Alibaba Cloud products, such as Container Service, use RESTful APIs. The method for calling a RESTful API differs from that of an RPC API. The basic structure for calling a RESTful API using the Cloud Assistant CLI is as follows:
-
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>