Updated on 2025-08-14 GMT+08:00

Adding a Trigger for an Object Instance

Function

This API is used to add a trigger for an object instance.

URI

POST Huawei Cloud Astro Zero domain name/u-route/baas/metadata/v1.0/Object/{object_id}/Trigger

Table 1 URI parameter

Parameter

Mandatory

Type

Description

object_id

Yes

String

Explanation

Object instance ID, which can be queried by calling the API of Querying All Custom Objects (id in the response message).

Constraints

None

Value

None

Default value

None

Request Parameters

Table 2 Request parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Explanation

Name of the trigger to be added.

Constraints

None

Value

Start with a letter and can contain only letters, digits, and single underscores (_). The value cannot use consecutive underscore (_) and cannot end with an underscore. A maximum of 64 characters are allowed.

Default value

None

label

No

String

Explanation

Label of the trigger to be added.

Constraints

None

Value

1–64 characters

Default value

None

description

No

String

Explanation

Description of the trigger.

Constraints

None

Value

1–255 characters

Default value

None

script

Yes

String

Explanation

Nameof the script that implements trigger functions.

Constraints

None

Value

None

Default value

None

jscode

No

string

Explanation

JavaScript code in the trigger.

Constraints

None

Value

None

Default value

None

active

No

String

Explanation

Whether to activate the trigger.

Constraints

None

Value

  • true: The license is activated.
  • false: The value is not activated.

Default value

false

event

No

String

Explanation

Conditions for starting a trigger.

Constraints

None

Value

  • BeforeInsert: Starts the trigger before inserting a record.
  • AfterInsert: Starts the trigger after a record is inserted.
  • BeforeUpdate: Starts the trigger before records are updated.
  • AfterUpdate: Starts the trigger after a record is updated.
  • BeforeDelete: Starts the trigger before a record is deleted.
  • AfterDelete: Starts the trigger after a record is deleted.

Default value

None

Response Parameters

Table 3 Response parameters

Parameter

Type

Description

resCode

String

Explanation

Return code.

Value

If the request is successful, 0 is returned. For details about other error codes, see Error Codes.

resMsg

String

Explanation

Message returned.

Value

If the request is successful, "Success" is returned. In other cases, an error message is returned.

result

string

Explanation

If the request is successful, an ID is returned.

Value

None

Example Request

To add a trigger for an object instance, send the following request:
POST https://Huawei Cloud Astro Zero domain name/u-route/baas/metadata/v1.0/Object/cust000000aKtFZpERvc/Trigger
{
    "name": "Trigger_01",
    "label": "Trigger 01",
    "description": null,
    "script": "string",
    "jscode": "Hello, world;rn",
    "active": true,
    "event": "BeforeInsert"
}

Example Response

{
    "resCode": "0",
    "resMsg": "Success",
    "result": "001i000000SIrEi3E0a8"
}

Status Code

See Status Codes.

Error Code

See Error Codes.