Help Center/ ServiceStage/ API Reference/ Examples/ Creating and Managing an Application
Updated on 2024-10-16 GMT+08:00

Creating and Managing an Application

Scenarios

An application is a service system with functions and consists of one or more components.

The following describes how to call the APIs for Creating an Application, Modifying Application Configurations Based on the Application ID, and Obtaining Application Details Based on the Application ID.

For details about how to call APIs, see Calling APIs.

Prerequisites

  • You have obtained the IAM user token by calling the API for obtaining a user token, and set the token to an environment variable, that is, export Token={token}.
  • You have obtained the ServiceStage endpoint to replace {servicestage_endpoint} in the following procedure. For details, see Regions and Endpoints.

Procedure

  1. Call the API for Creating an Application to create an application. The following is a request example:

    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"
            }
        ]
    }'

    Information similar to the following is displayed.

    {
        "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"
            }
        ]
    }

    Record the application ID in bold in the command output to replace {application_id} in subsequent examples.

  2. Call the API for Modifying Application Configurations Based on the Application ID to add an environment variable for the application. The following is a request example:

    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"
                }
            ]
        }
    }'

    Information similar to the following is displayed.

    {
        "application_id": "2c458700-c8e0-4651-a73b-5219b70a6572",
        "environment_id": "21a43958-f64f-4077-8ae3-3a03bf0111c7",
        "configuration": {
            "env": [
                {
                    "name": "testName",
                    "value": "testValue"
                }
            ]
        }
    }

  3. Call the API for Obtaining Application Details Based on the Application ID to query application details based on the application ID. The following is a request example:

    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}"

    Information similar to the following is displayed.

    {
        "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
    }