Updated on 2025-05-06 GMT+08:00

Creating an Event Subscription

Function

This API is used to create an event subscription.

URI

POST /v1/{project_id}/subscriptions

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Tenant resource space ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

enterprise_project_id

No

String

ID of an enterprise project used for creating a subscription.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. The token 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 the user token.

Table 4 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Name of the event subscription. The value must be unique under a tenant. Only letters, digits, periods (.), underscores (_), and hyphens (-) are allowed. It must start with a letter or digit.

description

No

String

Description of the event subscription.

channel_id

Yes

String

ID of the event channel to which the event subscription belongs.

sources

Yes

Array of SubscriptionSource objects

List of event subscription sources. Currently, only one event source can be subscribed to.

targets

Yes

Array of SubscriptionTarget objects

List of event subscription targets. At least one event target must be subscribed to.

Table 5 SubscriptionSource

Parameter

Mandatory

Type

Description

id

No

String

ID of the subscription source, which must be globally unique. If the subscription source with the specified ID exists, the subscription source is updated. Otherwise, the subscription source is created. If no ID is specified, the system automatically generates an ID when creating the subscription source. Only lowercase letters, digits, and hyphens (-) are allowed. It must start with a letter or digit.

name

Yes

String

Name of the event subscription source.

provider_type

Yes

String

Provider type of the event subscription source.

detail

No

Object

List of event subscription source parameters. The total length of this field after serialization cannot exceed 1024 bytes.

filter

Yes

Object

Filtering rule of the event subscription source. The total length of this field after serialization cannot exceed 2048 bytes.

Table 6 SubscriptionTarget

Parameter

Mandatory

Type

Description

id

No

String

Subscription target ID. The value must be globally unique. Only lowercase letters, digits, and hyphens (-) are allowed. It must start with a letter or digit. In the subscription update scenario, if the subscription target with the specified ID exists, the subscription target is updated. Otherwise, the subscription target is created. If no ID is specified, the system automatically generates an ID when creating the subscription target. If an ID is specified, the ID is used as the subscription target ID. This field is ignored when the subscription target is updated.

name

Yes

String

Name of the event subscription target.

provider_type

Yes

String

Provider type of the event subscription target.

connection_id

No

String

Connection ID used by the event subscription target.

detail

No

Object

List of event target parameters for the subscription. The total length cannot exceed 1,024 bytes after serialization. This field is mandatory for function (urn, invoke_type, and agency_name), function flow (workflow_id and agency_name), and webhook (url) targets. An agency name must be specified for a function or function flow.

kafka_detail

No

KafkaTargetDetail object

List of Kafka event subscription target parameters. The total length of this field after serialization cannot exceed 1024 bytes.

smn_detail

No

SmnTargetDetail object

List of SMN event target parameters for the subscription. The total length cannot exceed 1024 bytes after serialization.

eg_detail

No

EgTargetDetail object

List of EG event channel target parameters for the subscription. The total length cannot exceed 1,024 bytes after serialization. This field is mandatory for EG channel event targets.

apigw_detail

No

ApigwTargetDetail object

List of APIGW URL target parameters for the subscription. The total length cannot exceed 1,024 bytes after serialization. This field is mandatory for APIGW event targets.

retry_times

No

Integer

Number of retries.

transform

Yes

TransForm object

Transform rule of the event subscription target.

dead_letter_queue

No

DeadLetterQueue object

List of dead letter queue parameters for the subscription.

Table 7 KafkaTargetDetail

Parameter

Mandatory

Type

Description

topic

Yes

String

Topic.

keyTransform

No

keyTransform object

Key value rule.

Table 8 keyTransform

Parameter

Mandatory

Type

Description

type

No

String

Type of the key value rule.

value

No

String

Key value rule. This parameter is mandatory when type is VARIABLE or CONSTANT.

template

No

String

Key value rule template. This parameter is mandatory when type is VARIABLE.

Table 9 SmnTargetDetail

Parameter

Mandatory

Type

Description

urn

Yes

String

Specifies the topic URN.

agency_name

Yes

String

Agency name.

subject_transform

No

subject_transform object

Title rule.

Table 10 subject_transform

Parameter

Mandatory

Type

Description

type

Yes

String

Type of the title rule.

value

Yes

String

Title rule.

template

No

String

Title rule template. This parameter is mandatory when type is set to VARIABLE.

Table 11 EgTargetDetail

Parameter

Mandatory

Type

Description

target_project_id

Yes

String

Target project ID.

target_channel_id

Yes

String

Target channel ID.

target_region

Yes

String

Target region.

cross_region

No

Boolean

Indicates whether cross-region feature is enabled.

cross_account

No

Boolean

Indicates whether cross-account feature is enabled.

agency_name

Yes

String

Agency name.

Table 12 ApigwTargetDetail

Parameter

Mandatory

Type

Description

url

Yes

String

Target URL.

invocation_http_parameters

No

InvocationHttpParameters object

Parameters for invoking HTTP.

Table 13 InvocationHttpParameters

Parameter

Mandatory

Type

Description

header_parameters

No

Array of HeaderParameter objects

Object list.

Table 14 HeaderParameter

Parameter

Mandatory

Type

Description

is_value_secret

No

Boolean

Whether to encrypt the value.

key

No

String

Header key.

value

No

String

Header value.

Table 15 TransForm

Parameter

Mandatory

Type

Description

type

Yes

String

Type of the transform rule.

value

No

String

For a constant type rule, the field is the constant content definition.

For a variable type rule, the field is a variable definition and the content must be a JSON object string.

A maximum of 100 variables are supported, and nested structures are not supported.

The variable name can contain a maximum of 64 characters. Only letters, digits, periods (.), underscores (_), and hyphens (-) are allowed. It must start with a letter or digit and cannot start with HC..

The variable value expression can be a constant or JSONPath expression. The string length cannot exceed 1024 characters.

template

No

String

Template definition of the rule content when the rule is of the variable type. Defined variables can be referenced.

Table 16 DeadLetterQueue

Parameter

Mandatory

Type

Description

type

Yes

String

Queue type.

instance_id

Yes

String

Instance ID.

connection_id

Yes

String

Connection ID.

topic

Yes

String

Topic.

Response Parameters

Status code: 200

Table 17 Response header parameters

Parameter

Type

Description

X-Request-Id

String

This field is the request ID number for task tracking. Format is request_uuid-timestamp-hostname.

Table 18 Response body parameters

Parameter

Type

Description

id

String

Subscription ID.

name

String

Subscription name.

description

String

Description of the subscription.

type

String

Subscription type.

status

String

Status.

channel_id

String

ID of the event channel.

channel_name

String

Name of the event channel.

used

Array of SubscriptionUsedInfo objects

Label information.

sources

Array of SubscriptionSourceInfo objects

List of subscription sources.

targets

Array of SubscriptionTargetInfo objects

List of subscription targets.

created_time

String

Time when the trigger is created.

updated_time

String

Time when the trigger is updated.

Table 19 SubscriptionUsedInfo

Parameter

Type

Description

resource_id

String

Associated resource ID.

owner

String

Management tenant account.

description

String

Description.

Table 20 SubscriptionSourceInfo

Parameter

Type

Description

id

String

ID of the event subscription source.

name

String

Name of the event subscription source.

provider_type

String

Provider type of the event subscription source.

detail

Object

List of event subscription source parameters.

filter

Object

Filtering rule of the event subscription source.

created_time

String

Time when the event subscription is created.

updated_time

String

Time when the event subscription is updated.

Table 21 SubscriptionTargetInfo

Parameter

Type

Description

id

String

ID of the event subscription target.

name

String

Name of the event subscription target.

provider_type

String

Provider type of the event subscription target.

connection_id

String

Connection ID used by the event subscription target.

detail

Object

List of event subscription target parameters.

kafka_detail

KafkaTargetDetail object

List of Kafka event subscription target parameters. The total length of this field after serialization cannot exceed 1024 bytes.

smn_detail

SmnTargetDetail object

List of SMN event target parameters for the subscription. The total length cannot exceed 1024 bytes after serialization.

eg_detail

EgTargetDetail object

List of EG event channel target parameters for the subscription. The total length cannot exceed 1,024 bytes after serialization. This field is mandatory for EG channel event targets.

apigw_detail

ApigwTargetDetail object

List of APIGW URL target parameters for the subscription. The total length cannot exceed 1,024 bytes after serialization. This field is mandatory for APIGW event targets.

retry_times

Integer

Number of retries.

transform

TransForm object

Transform rule of the event subscription target.

dead_letter_queue

DeadLetterQueue object

List of dead letter queue parameters for the subscription.

created_time

String

Time when the event subscription is created.

updated_time

String

Time when the event subscription is updated.

Table 22 KafkaTargetDetail

Parameter

Type

Description

topic

String

Topic.

keyTransform

keyTransform object

Key value rule.

Table 23 keyTransform

Parameter

Type

Description

type

String

Type of the key value rule.

value

String

Key value rule. This parameter is mandatory when type is VARIABLE or CONSTANT.

template

String

Key value rule template. This parameter is mandatory when type is VARIABLE.

Table 24 SmnTargetDetail

Parameter

Type

Description

urn

String

Specifies the topic URN.

agency_name

String

Agency name.

subject_transform

subject_transform object

Title rule.

Table 25 subject_transform

Parameter

Type

Description

type

String

Type of the title rule.

value

String

Title rule.

template

String

Title rule template. This parameter is mandatory when type is set to VARIABLE.

Table 26 EgTargetDetail

Parameter

Type

Description

target_project_id

String

Target project ID.

target_channel_id

String

Target channel ID.

target_region

String

Target region.

cross_region

Boolean

Indicates whether cross-region feature is enabled.

cross_account

Boolean

Indicates whether cross-account feature is enabled.

agency_name

String

Agency name.

Table 27 ApigwTargetDetail

Parameter

Type

Description

url

String

Target URL.

invocation_http_parameters

InvocationHttpParameters object

Parameters for invoking HTTP.

Table 28 InvocationHttpParameters

Parameter

Type

Description

header_parameters

Array of HeaderParameter objects

Object list.

Table 29 HeaderParameter

Parameter

Type

Description

is_value_secret

Boolean

Whether to encrypt the value.

key

String

Header key.

value

String

Header value.

Table 30 TransForm

Parameter

Type

Description

type

String

Type of the transform rule.

value

String

For a constant type rule, the field is the constant content definition.

For a variable type rule, the field is a variable definition and the content must be a JSON object string.

A maximum of 100 variables are supported, and nested structures are not supported.

The variable name can contain a maximum of 64 characters. Only letters, digits, periods (.), underscores (_), and hyphens (-) are allowed. It must start with a letter or digit and cannot start with HC..

The variable value expression can be a constant or JSONPath expression. The string length cannot exceed 1024 characters.

template

String

Template definition of the rule content when the rule is of the variable type. Defined variables can be referenced.

Table 31 DeadLetterQueue

Parameter

Type

Description

type

String

Queue type.

instance_id

String

Instance ID.

connection_id

String

Connection ID.

topic

String

Topic.

Example Requests

Create an event subscription named test-subscription.

POST https://{endpoint}/v1/{project_id}/subscriptions

{
  "name" : "test-subscription",
  "description" : "this is a test subscription",
  "channel_id" : "05649f9a-b324-4920-9c49-156d4cd2e546",
  "sources" : [ {
    "id" : "3a0eeff2-78a4-4122-dfge-7ty5e37f64er",
    "name" : "HC.OBS",
    "provider_type" : "OFFICIAL",
    "detail" : {
      "name" : "name"
    },
    "filter" : {
      "data" : {
        "count" : [ {
          "op" : "NumberIn",
          "values" : [ 1, 2 ]
        } ]
      }
    }
  } ],
  "targets" : [ {
    "id" : "3a0eeff2-78a4-4122-dfge-7ty5e37f64er",
    "name" : "WEBHOOK",
    "provider_type" : "CUSTOM",
    "connection_id" : "456eekj3-778u-4tyu-dfrt-er55e37f667t",
    "detail" : {
      "url" : "http://10.213.96.90:8080/t/nodeapp/trigger-hello-nodejs",
      "agency_name" : "EG_TARGET_AGENCY",
      "urn" : "urn:fss:cn-north-7:bac852160cc743158936edaab6dda813:function:default:gxtestjava:latest",
      "invoke_type" : "ASYNC",
      "workflow_id" : "86afc904-0019-46c8-baed-0225967c1b98"
    },
    "kafka_detail" : {
      "topic" : "8516d278-268a-4a8b-8766-9bf9b3302f43",
      "keyTransform" : {
        "type" : "NONE",
        "value" : "string",
        "template" : "string"
      }
    },
    "smn_detail" : {
      "urn" : "urn:smn:cn-north-7:bac852160cc743158936edaab6dda813:122",
      "agency_name" : "EG_SMN_PUBLISHER_AGENCY",
      "subject_transform" : {
        "type" : "VARIABLE",
        "value" : "string",
        "template" : "string"
      }
    },
    "eg_detail" : {
      "target_project_id" : "c5be311886934b7c8afb4f8970376130",
      "target_channel_id" : "10a79a30-bd4a-4955-a3ec-d62dc799347b",
      "target_region" : "cn-north-test",
      "cross_region" : false,
      "cross_account" : false,
      "agency_name" : "EG_TARGET_AGENCY"
    },
    "apigw_detail" : {
      "url" : "https://dms.cn-north-4.myhuaweicloud.com/testaaa",
      "invocation_http_parameters" : {
        "header_parameters" : [ {
          "is_value_secret" : false,
          "key" : "test-key",
          "value" : "test-value"
        } ]
      }
    },
    "retry_times" : 16,
    "transform" : {
      "type" : "VARIABLE",
      "value" : "{\"contant_boolean\": true,\"contant_string\": \"constant\",\"varaible_string\": \"$.data.string\",\"varaible_json_object\": \"$.data.object\"}",
      "template" : "{\"contant_boolean\": ${contant_boolean},\"contant_string\": \"${contant_string!\\\"default\\\"}\",\"varaible_string\": \"${contant_boolean}\",\"varaible_json_object\": ${varaible_json_object!\"null\"}}"
    },
    "dead_letter_queue" : {
      "type" : "KAFKA",
      "instance_id" : "ff0e3f10-fcab-4c3a-84bb-cf5a8b6f7722",
      "connection_id" : "8516d278-268a-4a8b-8766-9bf9b3302f43",
      "topic" : "topic"
    }
  } ]
}

Example Responses

Status code: 200

Demo Information

{
  "id" : "23709d68-54d5-423b-a6be-03302e893152",
  "name" : "test-subscription",
  "description" : "this is a test subscription",
  "type" : "EVENT",
  "status" : "CREATED",
  "channel_id" : "05649f9a-b324-4920-9c49-156d4cd2e546",
  "channel_name" : "channel006",
  "used" : [ { } ],
  "sources" : [ { } ],
  "targets" : [ { } ],
  "created_time" : "2021-12-09 09:00:00",
  "updated_time" : "2021-12-09 09:00:00"
}

Status Codes

Status Code

Description

200

Demo Information

Error Codes

See Error Codes.