The styles of Alibaba Cloud service APIs are remote procedure call (RPC) and RESTful. The APIs of most Alibaba Cloud services are in the RPC style. When you use Alibaba Cloud CLI to call an API operation, the call method varies based on the API style.
Check the API style
Before you call an API operation, you must check the API style and then initiate the call based on the corresponding syntax. You can use one of the following methods to check the API style:
Add
--help
after the code of an Alibaba Cloud service in the command to obtain the API operations of the Alibaba Cloud service. If a brief description is returned, the API style is RPC. If thePathPattern
parameter that indicates the request path is returned, the API style is RESTful.Add
--help
after the name of an API operation in the command to obtain parameters of an API operation. If theMethod
andPathPattern
parameters are returned, which indicate the request method and request path of the API operation, the API style is RESTful.In most cases, all API operations of a service use the same API style. Each API supports only one style. If you pass an invalid identifier, another API operation may be called, or the
ApiNotFound
error is returned.
Call an RPC API operation
Syntax
The following code describes the syntax of the command that is used to call an RPC API operation by using Alibaba Cloud CLI:
aliyun <product> <APIName> [--parameter1 value1 --parameter2 value2 ...]
product
: the code of the Alibaba Cloud service whose API you want to call. For example, the code of Elastic Compute Service (ECS) isecs
.APIName
: the name of the API operation that you want to call. For example, you can call theDescribeRegions
operation of ECS.--parameter
: the request parameters that you must specify. You can view the details of the request parameters in the API reference of each Alibaba Cloud service.You can use the
--help
command to obtain the help information about the preceding parameters. For more information, see Use the help command.
Examples
In this example, the
DescribeRegions
operation of ECS is called. For more information, see DescribeRegions.aliyun ecs DescribeRegions
In this example, the
DescribeInstanceAttribute
operation of ECS is called. For more information, see DescribeInstanceAttribute.aliyun rds DescribeInstanceAttribute --InstanceId 'i-uf6f5trc95ug8t33****'
Call a RESTful API operation
Syntax
The following code describes the syntax of the command that is used to call a RESTful API operation by using Alibaba Cloud CLI:
aliyun <product> <Method> <PathPattern> --body <RequestBody>
product
: the code of the Alibaba Cloud service whose API you want to call. For example, the code of Container Service for Kubernetes (ACK) iscs
.Method
: the request method. Common request methods includeGET
,PUT
,POST
, andDELETE
. You can select an appropriate request method based on the API reference.PathPattern
: the request path. You can specify a valid request path based on the API reference.RequestBody
: the request body. The value is a JSON string. You can edit the JSON string based on the API reference, or reference a JSON file.You can use the
--help
command to obtain the help information about the preceding parameters. For more information, see Use the help command.
Examples
GET request
In this example, the DescribeClusterDetail
operation of Container Service for Kubernetes is called. For more information, see DescribeClusterDetail.
aliyun cs GET /clusters/{cluster_id}
PUT request
In this example, the ModifyCluster
operation of Container Service for Kubernetes is called. For more information, see ModifyCluster.
aliyun cs PUT /api/v2/clusters/{ClusterId} --header "Content-Type=application/json" --body "$(cat input.json)"
POST request
In this example, the CreateCluster
operation of Container Service for Kubernetes is called. For more information, see CreateCluster.
aliyun cs POST /clusters --header "Content-Type=application/json" --body "$(cat create.json)"
DELETE request
In this example, the DeleteClusterNodepool
operation of Container Service for Kubernetes is called. For more information, see DeleteClusterNodepool.
aliyun cs DELETE /clusters/{ClusterId}/nodepools/{NodepoolId}