
# 查询服务列表 - ListServices
#### 功能介绍
获取所有的服务详情
#### 调试
您可以在[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/IEF/doc?api=ListServices)中调试该接口，支持自动认证鉴权。API Explorer可以自动生成SDK代码示例，并提供SDK代码示例调试功能。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-ief/ief_02_1003.html)。
#### URI
GET /v2/{project_id}/edgemgr/services
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述   |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID |
表2Query参数 
| 参数     | 是否必选 | 参数类型   | 描述                         |
|:---|:---|:---|:---|
| limit  | 否    | Long   | 指定分页查询每页的行数，最大为100，默认值为10。 |
| offset | 否    | Long   | 指定要查询的偏移数量，默认为0。           |
| sorted | 否    | String | 响应中查询到的服务将按照指定的字段进行排序      |
| name   | 否    | String | 服务名称                       |
| app    | 否    | String | 按照相关的应用查询服务                |
#### 请求参数
表3请求Header参数 
| 参数              | 是否必选 | 参数类型   | 描述                                                        |
|:---|:---|:---|:---|
| Content-Type    | 是    | String | 消息体的类型（格式），默认取值为"application/json"。                       |
| X-Auth-Token    | 是    | String | 用户Token。 通过调用IAM服务获取用户Token接口获取（响应消息头中X-Subject-Token的值）。 |
| ief-instance-id | 是    | String | 企业版实例ID                                                   |
   
#### 响应参数
**状态码：200**
表4响应Body参数 
| 参数       | 参数类型                                                                            | 描述        |
|:---|:---|:---|
| count    | Long                                                                            | 满足条件的端点个数 |
| services | Array of [ServiceRespDetail] objects | 服务列表      |
   
 表5ServiceRespDetail 
| 参数         | 参数类型                                                      | 描述      |
|:---|:---|:---|
| created_at | String                                                    | 创建时间    |
| id         | String                                                    | 服务ID    |
| meta_data  | [SvcMetadata] object | 服务详情    |
| project_id | String                                                    | 租户ID    |
| spec       | [SvcSpec] object         | 服务的动态属性 |
| updated_at | String                                                    | 更新时间    |
   
 表6SvcMetadata 
| 参数     | 参数类型                 | 描述                                              |
|:---|:---|:---|
| labels | Map\<String,String\> | 自定义标签属性列表                                       |
| name   | String               | 服务名称，只允许英文小写字母、数字、中划线，最大长度64，英文小写字母开头，数字或小写字母结尾 |
   
 表7SvcSpec 
| 参数            | 参数类型                                                        | 描述                             |
|:---|:---|:---|
| cluster_ip    | String                                                      | 虚拟服务IP地址                       |
| external_ips  | Array of strings                                            | 外部IP列表 --- 暂不支持                |
| external_name | String                                                      | 外部域名 --- 暂不支持                  |
| ports         | Array of [SvcPort] objects | 服务需要暴露的端口列表                    |
| selector      | Map\<String,String\>                                        | 标签选择器，将选择具有指定Label标签的Pod作为管理范围 |
| type          | String                                                      | 服务的类型，仅支持填写：ClusterIP          |
   
 表8SvcPort 
| 参数          | 参数类型   | 描述                                                                                                                                                            |
|:---|:---|:---|
| name        | String | 服务端口必须进行命名，而且名称只允许是{protocol}-{suffix}这种格式，其中{protocol}可以是tcp、http等，IEF根据在端口上定义的协议来提供对应的路由能力。例如"name:http-0"和"name:tcp-0"是合法的端口名，"name:http2forecast"是非法的端口号。 |
| node_port   | String | 当spec.type=NodePort时，指定映射到物理机的端口号                                                                                                                             |
| port        | String | 服务监听的端口号                                                                                                                                                      |
| protocol    | String | 具体的协议，比如TCP                                                                                                                                                   |
| target_port | String | 需要转发到后端Pod的端口号                                                                                                                                                |
   
**状态码：500**
表9响应Body参数 
| 参数         | 参数类型   | 描述     |
|:---|:---|:---|
| error_code | String | 错误码    |
| error_msg  | String | 错误描述信息 |
   
#### 请求示例
无
#### 响应示例
**状态码：200**
查询成功
```
{
  "count" : 1,
  "services" : [ {
    "id" : "3ca04e38-301d-425e-94eb-75ce7fe73efd",
    "project_id" : "ed202955e111444e8ced21a1bd75fc59",
    "meta_data" : {
      "name" : "example"
    },
    "spec" : {
      "selector" : {
        "app" : "example-app"
      },
      "ports" : [ {
        "name" : "http-0",
        "protocol" : "TCP",
        "port" : "8090",
        "target_port" : "8080"
      } ],
      "cluster_ip" : "None"
    },
    "created_at" : "2022-09-07 02:28:08.395511 +0000 UTC",
    "updated_at" : "2022-09-07 02:28:08.395511 +0000 UTC"
  } ]
}
```
#### 状态码
| 状态码 | 描述   |
|:---|:---|
| 200 | 查询成功 |
| 500 | 错误响应 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-ief/ErrorCode.html)。
