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

Adding a Validator for an Object Instance

Function

This API is used to add a validator for an object instance. When adding data to an object instance, you can define rules to verify the field values and logical relationships between fields to ensure the validity of the object data. For example, the name field cannot be left empty, and the value of MinPrice cannot be greater than that of maxPrice.

URI

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

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 validator.

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 validator.

Constraints

None

Value

1–80 characters

Default value

None

description

No

String

Explanation

Description of the validator.

Constraints

None

Value

None

Default value

None

active

Yes

String

Explanation

Activation status.

Constraints

If this parameter is passed, other parameters will be ignored. In other words, other attributes cannot be modified during activation or deactivation of the validator.

Value

  • true: activated.
  • false: not activated.

Default value

false

errorExpression

No

String

Explanation

Rule expression of the validator.

Constraints

None

Value

None

Default value

None

errorMessage

No

String

Explanation

Error information, that is, the information displayed when the verification fails.

Constraints

None

Value

None

Default value

None

errorLocation

No

String

Explanation

Location where the error information is displayed. Currently, the error information can be displayed only on the top of the page when this parameter is set to topOfPage.

Constraints

None

Value

topOfPage

Default value

topOfPage

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 validator for an object instance, send the following request:
POST https://Huawei Cloud Astro Zero domain name/u-route/baas/metadata/v1.0/Object/cust000000aKtFZpERvc/Validator
{
  "active": true,
  "name": "age",
  "label": "age",
  "errorExpression": "age__CST>10",
  "errorMessage": "The age is greater than 10.",
  "errorLocation": "topOfPage"
}

Example Response

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

Status Code

See Status Codes.

Error Code

See Error Codes.