
# 创建并管理应用
#### 操作场景
应用是一个功能相对完备的业务系统，由一个或多个特性相关的组件组成。
下面介绍如何调用[创建应用 - CreateApplication](https://support.huaweicloud.com/api-servicestage/servicestage_06_0067.html)API创建应用，再调用[根据应用ID修改应用配置 - ModifyApplicationConfigurationsBasedOnTheApplicationID](https://support.huaweicloud.com/api-servicestage/servicestage_06_0073.html)API为应用添加应用环境变量，最后调用[根据应用ID获取应用详细信息 - ObtainApplicationDetailsBasedOnTheApplicationID](https://support.huaweicloud.com/api-servicestage/servicestage_06_0071.html)API查询应用详细信息。
API的调用方法请参见[如何调用API](https://support.huaweicloud.com/api-servicestage/servicestage_06_0008.html)。
#### 前提条件
- 已调用[获取用户Token](https://support.huaweicloud.com/api-iam/iam_30_0001.html)获取IAM用户的Token，并将token值设置为环境变量：export Token={token}。
- 已获取ServiceStage的终端节点，详细信息请参见[地区和终端节点](https://console.huaweicloud.com/apiexplorer/#/endpoint/ServiceStage)，并用于替换以下操作步骤示例中的{servicestage_endpoint}。
 
#### 操作步骤
1. 调用[创建应用 - CreateApplication](https://support.huaweicloud.com/api-servicestage/servicestage_06_0067.html)API创建应用，请求示例如下：
   
   ```
   curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$Token" -X POST "https://{servicestage_endpoint}/v3/{project_id}/cas/applications" -d ' 
   {
       "name": "app-test-application",
       "description": "test application",
       "enterprise_project_id": "0",
       "labels": [
           {
               "key": "testKey",
               "value": "testValue"
           }
       ]
   }'
   ```
   返回结果：
   ```
   {
       "id": "2c458700-c8e0-4651-a73b-5219b70a6572",
       "name": "app-test-application",
       "description": "test application",
       "project_id": "063a3158b1a34710b36ad208b9497d00",
       "enterprise_project_id": "0",
       "creator": "test_user",
       "create_time": 1689575641705,
       "update_time": 1689575641705,
       "unified_model": null,
       "labels": [
           {
               "key": "testKey",
               "value": "testValue"
           }
       ]
   }
   ```
   记录返回结果中加粗显示的应用ID，用于替换后续示例中的{application_id}。
   
   
2. 调用[根据应用ID修改应用配置 - ModifyApplicationConfigurationsBasedOnTheApplicationID](https://support.huaweicloud.com/api-servicestage/servicestage_06_0073.html)API为应用添加应用环境变量，请求示例如下：
   
   ```
   curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$Token" -X PUT "https://{servicestage_endpoint}/v3/{project_id}/cas/applications/{application_id}/configuration" -d ' 
   {
       "environment_id": "21a43958-f64f-4077-8ae3-3a03bf0111c7",
       "configuration": {
           "env": [
               {
                   "name": "testName",
                   "value": "testValue"
               }
           ]
       }
   }'
   ```
   返回结果：
   ```
   {
       "application_id": "2c458700-c8e0-4651-a73b-5219b70a6572",
       "environment_id": "21a43958-f64f-4077-8ae3-3a03bf0111c7",
       "configuration": {
           "env": [
               {
                   "name": "testName",
                   "value": "testValue"
               }
           ]
       }
   }
   ```
   
   
3. 调用[根据应用ID获取应用详细信息 - ObtainApplicationDetailsBasedOnTheApplicationID](https://support.huaweicloud.com/api-servicestage/servicestage_06_0071.html)API根据应用ID查询应用详细信息，请求示例如下：
   
   ```
   curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$token" -X GET "https://{servicestage_endpoint}/v3/{project_id}/cas/applications/{application_id}"
   ```
   返回结果：
   ```
   {
       "id": "2c458700-c8e0-4651-a73b-5219b70a6572",
       "name": "app-test-application",
       "description": "test application",
       "project_id": "063a3158b1a34710b36ad208b9497d00",
       "enterprise_project_id": "0",
       "creator": "test_user",
       "create_time": 1689575641705,
       "update_time": 1689575641705,
       "unified_model": null,
       "labels": [
           {
               "key": "testKey",
               "value": "testValue"
           }
       ],
       "component_count": 0
   }
   ```
   
   
 
