
# 创建APP - CreateAnAppV2
#### 功能介绍
创建一个APP。APP即应用，是一个可以访问API的身份标识。将API授权给APP后，APP即可调用API。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-apig/apig-api-180713003.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-apig/apig-api-grant-policy_0000.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项             | 访问级别  | 资源类型（\*为必须） | 条件键                       | 别名               | 依赖的授权项            |
  |:---|:---|:---|:---|:---|:---|
  | apig:app:create | Write | instance \* | g:ResourceTag/\<tag-key\> | apig:apps:create | apig:instance:get |
     
  
 
#### URI
POST /v2/{project_id}/apigw/instances/{instance_id}/apps
表1路径参数 
| 参数          | 是否必选 | 参数类型   | 描述                                                                                      |
|:---|:---|:---|:---|
| project_id  | 是    | String | 项目ID，获取方式请参见[获取项目ID](https://support.huaweicloud.com/api-apig/apig-api-180713009.html)。 |
| instance_id | 是    | String | 实例ID，在API网关控制台的"实例信息"中获取。                                                               |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                       |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 用户Token。通过调用IAM服务获取用户Token接口获取（响应消息头中X-Subject-Token的值）。 |
   
表3请求Body参数 
| 参数                 | 是否必选 | 参数类型   | 描述                                                                                                                                                                          |
|:---|:---|:---|:---|
| name               | 是    | String | APP的名称。支持汉字，英文，数字，下划线，且只能以英文和汉字开头，3 \~ 64个字符。 说明： 中文字符必须为UTF-8或者unicode编码。                                                                 |
| remark             | 否    | String | APP描述。字符长度不能大于255。 说明： 中文字符必须为UTF-8或者unicode编码。                                                                                            |
| app_key            | 否    | String | APP凭据的key。支持英文，数字，"_"，"-"，且只能以英文或数字开头，8 \~ 200个字符。                                                                                                                          |
| app_secret         | 否    | String | 密钥。支持英文，数字，"_"，"-"，"!"，"@"，"#"，"$"，"%"，且只能以英文或数字开头，8 \~ 128个字符。                                                                                                             |
| related_domain_id  | 否    | String | 凭据关联的账号ID。通过AIAPIKey认证调用AI API时，需要关联账号ID（客户端）。 说明： 该参数属于AIAPIKey功能，需要开启白名单后才可以使用。 最小长度：**32** 最大长度：**36** |
| related_project_id | 否    | String | 凭据关联的项目ID。通过AIAPIKey认证调用AI API时，需要关联项目ID（客户端）。 说明： 该参数属于AIAPIKey功能，需要开启白名单后才可以使用。 最小长度：**32** 最大长度：**36** |
   
#### 响应参数
**状态码：201**
表4响应Body参数 
| 参数                 | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                        |
|:---|:---|:---|
| id                 | String  | 编号                                                                                                                                                                                                                                                                                                                                                                        |
| name               | String  | 名称                                                                                                                                                                                                                                                                                                                                                                        |
| remark             | String  | 描述                                                                                                                                                                                                                                                                                                                                                                        |
| creator            | String  | APP的创建者 - USER：用户自行创建   - MARKET：云商店分配    暂不支持MARKET          |
| update_time        | String  | 更新时间                                                                                                                                                                                                                                                                                                                                                                      |
| app_key            | String  | APP凭据的key。                                                                                                                                                                                                                                                                                                                                                                |
| related_domain_id  | String  | 凭据关联的账号ID。通过AIAPIKey认证调用AI API时，需要关联账号ID（客户端）。 说明： 该参数属于AIAPIKey功能，需要开启白名单后才可以使用。 最小长度：**32** 最大长度：**36**                                                                                                                                                                                               |
| related_project_id | String  | 凭据关联的项目ID。通过AIAPIKey认证调用AI API时，需要关联项目ID（客户端）。 说明： 该参数属于AIAPIKey功能，需要开启白名单后才可以使用。 最小长度：**32** 最大长度：**36**                                                                                                                                                                                               |
| app_secret         | String  | 密钥                                                                                                                                                                                                                                                                                                                                                                        |
| register_time      | String  | 注册时间                                                                                                                                                                                                                                                                                                                                                                      |
| status             | Integer | 状态 - 1： 有效                                                                                                                                                                         |
| app_type           | String  | APP的类型。 - apig：APIG凭据应用    默认apig，暂不支持其他类型                                                                                                                                         |
| roma_app_type      | String  | ROMA_APP的类型： - subscription：订阅应用   - integration：集成应用    暂不支持 |
   
**状态码：400**
表5响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
**状态码：401**
表6响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
**状态码：403**
表7响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
**状态码：500**
表8响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
#### 请求示例
创建一个app
```
{
  "name" : "app_demo",
  "remark" : "Demo app",
  "related_domain_id" : "123de8eb7a8742168586e5daf5339965",
  "related_project_id" : "234de8eb7a8742168586e5daf5339966"
}
```
#### 响应示例
**状态码：201**
Created
```
{
  "creator" : "USER",
  "update_time" : "2020-08-03T13:09:13.122211909Z",
  "app_key" : "ee8f878c252747028f07eb116c2cd91b",
  "name" : "app_demo",
  "remark" : "Demo app",
  "id" : "356de8eb7a8742168586e5daf5339965",
  "app_secret" : "416************ab8",
  "register_time" : "2020-08-03T13:09:13.122211659Z",
  "status" : 1,
  "app_type" : "apig",
  "related_domain_id" : "123de8eb7a8742168586e5daf5339965",
  "related_project_id" : "234de8eb7a8742168586e5daf5339966"
}
```
**状态码：400**
Bad Request
```
{
  "error_code" : "APIG.2011",
  "error_msg" : "Invalid parameter value,parameterName:name. Please refer to the support documentation"
}
```
**状态码：401**
Unauthorized
```
{
  "error_code" : "APIG.1002",
  "error_msg" : "Incorrect token or token resolution failed"
}
```
**状态码：403**
Forbidden
```
{
  "error_code" : "APIG.1005",
  "error_msg" : "No permissions to request this method"
}
```
**状态码：500**
Internal Server Error
```
{
  "error_code" : "APIG.9999",
  "error_msg" : "System error"
}
```
#### 状态码
| 状态码 | 描述                    |
|:---|:---|
| 201 | Created               |
| 400 | Bad Request           |
| 401 | Unauthorized          |
| 403 | Forbidden             |
| 500 | Internal Server Error |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-apig/ErrorCode.html)。
