Importing a Microservice

Function

This API is used to import a microservice.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/apigw/instances/{instance_id}/microservice/import

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain it, see Obtaining a Project ID.

instance_id

Yes

String

Gateway ID, which can be obtained from the gateway information on the APIG console.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is a token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

group_info

Yes

MicroserviceGroup object

Information about the API group to import a microservice to.

service_type

Yes

String

Microservice center type.

  • CSE: CSE microservice registration center

  • CCE: CCE workload

Enumeration values:

  • CSE

  • CCE

protocol

No

String

Request protocol used by APIG to access the microservice.

  • HTTP

  • HTTPS

Default: HTTPS

Enumeration values:

  • HTTP

  • HTTPS

apis

Yes

Array of MicroserviceApiCreate objects

Imported APIs.

Array Length: 1 - 50

backend_timeout

No

Integer

Timeout allowed for APIG to request the backend service. You can set the maximum timeout using the backend_timeout configuration item. The maximum value is 600,000, and the default value is 5000.

Unit: ms.

Minimum: 1

Default: 5000

auth_type

No

String

API authentication mode. By default, authentication is not required.

  • NONE

  • APP

  • IAM

Default: NONE

Enumeration values:

  • NONE

  • APP

  • IAM

cors

No

Boolean

Whether CORS is supported. By default, it is not supported.

  • true: Supported.

  • false: Not supported.

Default: false

Enumeration values:

  • true

  • false

cse_info

No

MicroServiceInfoCSECreate object

CSE microservice details. This parameter is required if service_type is set to CSE.

cce_info

No

MicroServiceInfoCCECreate object

CCE workload details. This parameter is required if service_type is set to CCE.

Table 4 MicroserviceGroup

Parameter

Mandatory

Type

Description

group_id

No

String

An existing group. If this parameter is left empty, a new group is created.

Minimum: 0

Maximum: 64

group_name

No

String

Name of the API group. This parameter is required when group_id is empty.

Enter 3 to 255 characters, starting with a letter or digit. Only letters, digits, and these special characters are allowed: -_./:()

Minimum: 3

Maximum: 255

app_id

No

String

Integration application to which the new group belongs. This parameter is required when group_id is empty.

Minimum: 0

Maximum: 64

Table 5 MicroserviceApiCreate

Parameter

Mandatory

Type

Description

name

No

String

API name.

Start with a letter or digit, and use only letters, digits, and these special characters: -_./:()

Minimum: 3

Maximum: 255

req_method

No

String

Request method.

Default: ANY

Enumeration values:

  • GET

  • POST

  • PUT

  • DELETE

  • HEAD

  • PATCH

  • OPTIONS

  • ANY

req_uri

Yes

String

Request address, which can contain request parameters enclosed with braces ({}). For example, /getUserInfo/{userId}. Special characters, such as asterisks (*), slashes (/), percent signs (%), hyphens (-), underscores (_), and periods (.), are allowed. It can contain a maximum of 512 characters and must comply with URI specifications.

/apic/health_check is the preset health check path of APIG. If req_method=GET is passed, req_uri=/apic/health_check is not supported.

Note

The address must comply with the URI specifications.

Minimum: 1

Maximum: 512

match_mode

No

String

API matching mode.

  • SWA: Prefix match.

  • NORMAL: Exact match.

Default value: NORMAL

Default: SWA

Enumeration values:

  • SWA

  • NORMAL

Table 6 MicroServiceInfoCSECreate

Parameter

Mandatory

Type

Description

engine_id

Yes

String

Microservice engine ID.

Maximum: 64

service_id

Yes

String

Microservice ID.

Maximum: 64

version

Yes

String

Microservice version.

Maximum: 64

Table 7 MicroServiceInfoCCECreate

Parameter

Mandatory

Type

Description

cluster_id

Yes

String

CCE cluster ID.

Maximum: 64

namespace

Yes

String

Namespace.

Maximum: 64

workload_type

Yes

String

Workload type.

  • deployment

  • statefulset

  • daemonset

Enumeration values:

  • deployment

  • statefulset

  • daemonset

app_name

No

String

App name. Start with a letter, and include only letters, digits, periods (.), hyphens (-), and underscores (_). (1 to 64 characters)

Minimum: 1

Maximum: 64

label_key

No

String

Service label key. Start with a letter or digit, and use only letters, digits, and these special characters: -_./:(). (1 to 64 characters)

Minimum: 1

Maximum: 64

label_value

No

String

Service label value. Start with a letter, and include only letters, digits, periods (.), hyphens (-), and underscores (_). (1 to 64 characters)

Minimum: 1

Maximum: 64

version

No

String

Workload version.

Maximum: 64

port

Yes

Integer

Listening port No. of the workload.

Minimum: 1

Maximum: 65535

labels

No

Array of MicroserviceLabel objects

Workload label list.

Table 8 MicroserviceLabel

Parameter

Mandatory

Type

Description

label_name

Yes

String

Tag name.

Start and end with a letter or digit. Use only letters, digits, hyphens (-), underscores (_), and periods (.). (Max. 63 characters.)

Minimum: 1

Maximum: 63

label_value

Yes

String

Tag value.

Start and end with a letter or digit. Use only letters, digits, hyphens (-), underscores (_), and periods (.). (Max. 63 characters.)

Minimum: 1

Maximum: 63

Response Parameters

Status code: 201

Table 9 Response body parameters

Parameter

Type

Description

vpc_channel_id

String

VPC channel ID.

api_group_id

String

API group ID.

apis

Array of MicroserviceImportApiResp objects

Imported APIs.

Table 10 MicroserviceImportApiResp

Parameter

Type

Description

name

String

API name.

req_uri

String

Request path.

req_method

String

Request method.

id

String

API ID.

match_mode

String

API matching mode.

  • SWA: Prefix match.

  • NORMAL: Exact match. Default value: SWA

Enumeration values:

  • SWA

  • NORMAL

Status code: 400

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 403

Table 13 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 404

Table 14 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 15 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

  • Importing a CSE microservice

    {
      "group_info" : {
        "group_id" : "6329eaa17736412b988536179cd8d662",
        "group_name" : "",
        "app_id" : ""
      },
      "service_type" : "CSE",
      "protocol" : "HTTPS",
      "apis" : [ {
        "name" : "api1",
        "req_method" : "ANY",
        "req_uri" : "/test",
        "match_mode" : "SWA"
      } ],
      "backend_timeout" : 5000,
      "auth_type" : "NONE",
      "cors" : false,
      "cse_info" : {
        "engine_id" : "fde2c21c-5bd9-40f0-ad6a-81e4b6782805a",
        "service_id" : "92919f98fba80c2df13cc285c983946c90e635ff",
        "version" : "1.0.0"
      }
    }
    
  • Importing a CCE Deployment

    {
      "group_info" : {
        "group_id" : "6329eaa17736412b988536179cd8d662",
        "group_name" : "",
        "app_id" : ""
      },
      "service_type" : "CCE",
      "protocol" : "HTTPS",
      "apis" : [ {
        "name" : "dp",
        "req_method" : "ANY",
        "req_uri" : "/test",
        "match_mode" : "SWA"
      } ],
      "backend_timeout" : 5000,
      "auth_type" : "NONE",
      "cors" : false,
      "cce_info" : {
        "cluster_id" : "11069278-f9f8-11ec-b1b2-0255ac100b06",
        "namespace" : "test",
        "workload_type" : "deployment",
        "app_name" : "dp",
        "port" : 80,
        "labels" : [ {
          "label_name" : "cluster_id",
          "label_value" : "c429700c-5dc4-482a-9c0e-99f6c0635113"
        } ]
      }
    }
    

Example Responses

Status code: 201

success

  • Example 1

    {
      "vpc_channel_id" : "9d075537ff314a5e8e5c98bf29549b89",
      "api_group_id" : "6329eaa17736412b988536179cd8d662",
      "apis" : [ {
        "id" : "72e667087fe140529f81995b213dadbe",
        "name" : "api1",
        "req_uri" : "/test",
        "req_method" : "ANY",
        "match_mode" : "SWA"
      } ]
    }
    
  • Example 2

    {
      "vpc_channel_id" : "3f56e9d4a747486caa4cfb59a47b6854",
      "api_group_id" : "6329eaa17736412b988536179cd8d662",
      "apis" : [ {
        "id" : "3b52e2c05710470b88e283deb0a805e6",
        "name" : "dp_b09d",
        "req_uri" : "/test",
        "req_method" : "ANY",
        "match_mode" : "SWA"
      } ]
    }
    

Status code: 400

Bad Request

{
  "error_code" : "APIG.2011",
  "error_msg" : "Invalid parameter value,parameterName:name. Please refer to the support documentation"
}

Status code: 401

Unauthorized

{
  "error_code" : "APIG.1002",
  "error_msg" : "Incorrect token or token resolution failed"
}

Status code: 403

Forbidden

{
  "error_code" : "APIG.1005",
  "error_msg" : "No permissions to request this method"
}

Status code: 404

Not Found

{
  "error_code" : "APIG.3030",
  "error_msg" : "The instance does not exist;id:f0fa1789-3b76-433b-a787-9892951c620ec"
}

Status code: 500

Internal Server Error

{
  "error_code" : "APIG.9999",
  "error_msg" : "System error"
}

Status Codes

Status Code

Description

201

success

400

Bad Request

401

Unauthorized

403

Forbidden

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.