# 获取云函数

[调试诊断](https://developers.weixin.qq.com/console/devtools/debug?utm_source=api_tools)

> 接口应在服务器端调用，不可在前端（小程序、网页、APP等）直接调用，具体可参考[接口调用指南](/doc/oplatform/developers/dev/guide.md)。

接口英文名：getCloudFunctionList

通过本接口可以获取云函数列表，使用过程中如遇到问题，可在[开放平台服务商专区](https://developers.weixin.qq.com/community/minihome/mixflow/1355698687267438595)发帖交流。

## 1. 调用方式

### HTTPS 调用

```bash
POST https://api.weixin.qq.com/componenttcb/getscflist?access_token=ACCESS_TOKEN
```

### 云调用

- 本接口不支持云调用。

### 第三方调用

- 本接口仅支持第三方平台使用 [component_access_token](/doc/oplatform/developers/dev/ComponentAccessToken.md) 自己调用。

## 2. 请求参数

### 查询参数 `Query String Parameters`

```json
[
  {
    "参数名": "access_token",
    "类型": "string",
    "必填": "是",
    "说明": "接口调用凭证，可使用 [component_access_token](/doc/oplatform/openApi/ticket-token/api_getcomponentaccesstoken)"
  }
]
```

### 请求体 `Request Payload`

```json
[
  {
    "参数名": "env",
    "类型": "string",
    "必填": "是",
    "说明": "环境ID"
  },
  {
    "参数名": "offset",
    "类型": "number",
    "必填": "否",
    "说明": "数据偏移量。默认值0"
  },
  {
    "参数名": "limit",
    "类型": "number",
    "必填": "否",
    "说明": "返回数据长度。默认值20"
  },
  {
    "参数名": "searchkey",
    "类型": "string",
    "必填": "否",
    "说明": "模糊匹配 functionName"
  }
]
```

## 3. 返回参数

### 返回体 `Response Payload`

```json
[
  {
    "参数名": "errcode",
    "类型": "number",
    "说明": "错误码"
  },
  {
    "参数名": "errmsg",
    "类型": "string",
    "说明": "错误信息"
  },
  {
    "参数名": "total_count",
    "类型": "number",
    "说明": "云函数个数"
  },
  {
    "参数名": "functions",
    "类型": "objarray",
    "说明": "云函数信息"
  }
]
```

">

### Res.functions(Array) `Object Payload`

云函数信息

```json
[
  {
    "参数名": "mod_time",
    "类型": "string",
    "说明": "修改时间"
  },
  {
    "参数名": "add_time",
    "类型": "string",
    "说明": "添加时间"
  },
  {
    "参数名": "runtime",
    "类型": "string",
    "说明": "Nodejs8.9"
  },
  {
    "参数名": "name",
    "类型": "string",
    "说明": "名称"
  },
  {
    "参数名": "status",
    "类型": "string",
    "说明": "状态CreateFailed"
  },
  {
    "参数名": "status_reason",
    "类型": "objarray",
    "说明": "原因"
  }
]
```

__status_reason">

### Res.functions(Array).status_reason `Object Payload`

原因

```json
[
  {
    "参数名": "errcode",
    "类型": "string",
    "说明": "错误码"
  },
  {
    "参数名": "errmsg",
    "类型": "string",
    "说明": "错误信息"
  }
]
```

## 4. 注意事项

本接口无特殊注意事项

## 5. 代码示例

请求示例

```json
{
  "env": "myttest-8gu57so0bd9f9e8a"
}
```

返回示例

```json
{
  "errcode": 0,
  "errmsg": "ok",
  "total_count": 2,
  "functions": [
    {
      "mod_time": "2021-07-29 15:04:19",
      "add_time": "2021-07-29 15:04:19",
      "runtime": "Nodejs8.9",
      "name": "testfunc5",
      "status": "CreateFailed",
      "status_reason": [
        {
          "errcode": "ResourceNotFound.File",
          "errmsg": "未找到函数执行入口文件，请确认代码包入口文件名和 handler 设置是否对应或代码压缩包是否正常。"
        }
      ]
    },
    {
      "mod_time": "2021-07-29 14:41:43",
      "add_time": "2021-07-29 14:41:43",
      "runtime": "Nodejs8.9",
      "name": "testfunc4",
      "status": "Active",
      "status_reason": []
    }
  ]
}
```

## 6. 错误码

以下是本接口的错误码列表，其他错误码可参考 [通用错误码](/doc/oplatform/developers/errCode/README.md)；调用接口遇到报错，可使用官方提供的 [API 诊断工具](https://developers.weixin.qq.com/console/devtools/debug?utm_source=api_errcode) 辅助定位和分析问题。

```json
[
  {
    "错误码": "47001",
    "错误描述": "data format error",
    "解决方案": "解析 JSON/XML 内容错误;post 数据中参数缺失;检查修正后重试。"
  },
  {
    "错误码": "85088",
    "错误描述": "no qbase privilege",
    "解决方案": "该APP未开通云开发"
  }
]
```

## 7. 适用范围

本接口支持「第三方平台」账号类型代调用，权限集请参考「调用方式」部分。其他账号类型如无特殊说明，均不可调用。
