
# 查询API版本列表信息 - ListApiVersions
#### 功能介绍
查询当前ELB服务所有可用的API版本。通常情况下高版本API（当前v3为最高版本）比低版本API支持更多更全的特性。
不同版本接口使用时需要注意如下事项：
- 创建负载均衡器（POST /v3/{project_id}/elb/loadbalancers）接口无法创建共享型ELB实例。需要通过v2/v2.0接口创建，或者通过批量创建负载均衡器（/v3/{project_id}/elb/loadbalancers/batch-create）、复制已有负载均衡器（/v3/{project_id}/elb/loadbalancers/{loadbalancer_id}/clone）这两个接口创建。
  
- 其他v3接口都可以同时处理独享型和共享型实例及其子资源。例如：可以使用创建监听器接口（POST /v3/{project_id}/elb/listeners）创建共享型ELB下的监听器。但在这种情况下部分独享型实例特有的特性将不会支持，具体见各API说明。
  
 
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-elb/elb_dy_0000.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-elb/elb_sq_0001.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
 
#### URI
GET /versions
#### 请求参数
无
#### 响应参数
**状态码：200**
表1响应Body参数 
| 参数       | 参数类型                                                                         | 描述                  |
|:---|:---|:---|
| versions | Array of [ApiVersionInfo] objects | **参数解释**：可用API版本列表。 |
   
 表2ApiVersionInfo 
| 参数     | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
|:---|:---|:---|
| id     | String | **参数解释**：API版本号。 **取值范围**：由高到低版本分别为v3，v2，v2.0。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| status | String | **参数解释**：API版本的状态。 **取值范围**： - CURRENT：当前版本，当前所支持的API版本中最高的版本。   - STABLE：稳定版本，其他可用版本。   - DEPRECATED：废弃版本。    |
   
#### 请求示例
查询负载均衡服务的API版本列表信息
```
GET https://{ELB_Endpoint}/versions
```
#### 响应示例
**状态码：200**
操作正常返回。
```
{
  "versions" : [ {
    "id" : "v3",
    "status" : "CURRENT"
  }, {
    "id" : "v2",
    "status" : "STABLE"
  }, {
    "id" : "v2.0",
    "status" : "STABLE"
  } ]
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  package com.huaweicloud.sdk.test;
  import com.huaweicloud.sdk.core.auth.ICredential;
  import com.huaweicloud.sdk.core.auth.BasicCredentials;
  import com.huaweicloud.sdk.core.exception.ConnectionException;
  import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
  import com.huaweicloud.sdk.core.exception.ServiceResponseException;
  import com.huaweicloud.sdk.elb.v3.region.ElbRegion;
  import com.huaweicloud.sdk.elb.v3.*;
  import com.huaweicloud.sdk.elb.v3.model.*;
  public class ListApiVersionsSolution {
      public static void main(String[] args) {
          // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
          // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
          String ak = System.getenv("CLOUD_SDK_AK");
          String sk = System.getenv("CLOUD_SDK_SK");
          ICredential auth = new BasicCredentials()
                  .withAk(ak)
                  .withSk(sk);
          ElbClient client = ElbClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                  .build();
          ListApiVersionsRequest request = new ListApiVersionsRequest();
          try {
              ListApiVersionsResponse response = client.listApiVersions(request);
              System.out.println(response.toString());
          } catch (ConnectionException e) {
              e.printStackTrace();
          } catch (RequestTimeoutException e) {
              e.printStackTrace();
          } catch (ServiceResponseException e) {
              e.printStackTrace();
              System.out.println(e.getHttpStatusCode());
              System.out.println(e.getRequestId());
              System.out.println(e.getErrorCode());
              System.out.println(e.getErrorMsg());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkelb.v3 import *
  if __name__ == "__main__":
      # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak = os.environ["CLOUD_SDK_AK"]
      sk = os.environ["CLOUD_SDK_SK"]
      credentials = BasicCredentials(ak, sk)
      client = ElbClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(ElbRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ListApiVersionsRequest()
          response = client.list_api_versions(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region"
  )
  func main() {
      // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak := os.Getenv("CLOUD_SDK_AK")
      sk := os.Getenv("CLOUD_SDK_SK")
      auth, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := elb.ElbClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := elb.NewElbClient(hcClient)
      request := &model.ListApiVersionsRequest{}
  response, err := client.ListApiVersions(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/ELB/sdk?api=ListApiVersions&version=v3)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述      |
|:---|:---|
| 200 | 操作正常返回。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-elb/ErrorCode.html)。
