Help Center> Simple Message Notification> API Reference> APIs> Tags> Adding or Deleting Resource Tags in Batches
Updated on 2024-04-19 GMT+08:00

Adding or Deleting Resource Tags in Batches

Function

This API is used to add or delete tags in batches for a specified resource. You can add a maximum of 10 tags to a resource. The API is idempotent. When you are creating tags, if there are duplicate keys in the request body, an error is reported. If a to-be-created tag has the same key as an existing tag, the tag will be created and overwrite the existing one. During tag deletion, if some tags do not exist, the deletion is considered to be successful by default. The character set of the tags will not be checked.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/{resource_type}/{resource_id}/tags/action

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.For details about how to obtain the project ID, see Obtaining the Project ID.

resource_type

Yes

String

Specifies the resource type. Possible values are:

smn_topic: topic

smn_sms: SMS

smn_application: mobile push

resource_id

Yes

String

Specifies the resource ID.

To obtain the value of resource_id, perform the following steps:

When resource_type is set to smn_topic: Add X-SMN-RESOURCEID-TYPE=name in the request header and set the resource ID to the topic name. Call the GetResourceInstances API to obtain the resource ID. If you set resource_type to smn_sms, the resource ID is the signature ID, which can be obtained on the console.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies a user token.

It can be obtained by calling an IAM API. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

tags

Yes

Array of ResourceTag objects

Specifies the tag list. For details, see table 1. When you delete tags, the tag structure cannot be missing, and the key cannot be left blank or be an empty string. The system does not check the character set when deleting a tag.

action

Yes

String

Specifies the operation to be performed. The value can be create or delete only.

Table 4 ResourceTag

Parameter

Mandatory

Type

Description

key

Yes

String

Specifies the key field to be matched.

key can only be resource_name. In such a case, value is the ECS name.

  • The key must be unique, and the value is used for matching.

  • The key field is a fixed dictionary value.

  • key cannot be left blank.

value

Yes

String

Specifies the value.

key can only be resource_name. In such a case, value is the ECS name.

  • It can contain a maximum of 255 Unicode characters.

  • This field cannot be left blank.

Response Parameters

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Status code: 403

Table 6 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Status code: 404

Table 7 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Status code: 500

Table 8 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID, which is unique.

code

String

Specifies the error code.

message

String

Describes the error message.

Example Requests

  • Batch adding tags to resources

    POST https://{SMN_Endpoint}/v2/{project_id}/{resource_type}/{resource_id}/tags/action
    
    {
      "action" : "create",
      "tags" : [ {
        "key" : "key1",
        "value" : "value1"
      }, {
        "key" : "key",
        "value" : "value3"
      } ]
    }
  • Batch deleting resource tags

    POST https://{SMN_Endpoint}/v2/{project_id}/{resource_type}/{resource_id}/tags/action
    
    {
      "action" : "delete",
      "tags" : [ {
        "key" : "key1"
      }, {
        "key" : "key2",
        "value" : "value3"
      } ]
    }

Example Responses

None

Status Codes

Status Code

Description

204

OK

400

Bad Request

403

Unauthorized

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.