# Adding or Deleting Resource Tags in Batches

#### Description

- API name

  BatchCreateOrDeleteResourceTags

- Function

  Add or delete tags for a specified resource in batches.

  You can add a maximum of 10 tags to a resource.

  The API is idempotent. When you are to create 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.

  When tags are being deleted and some tags do not exist, the operation is considered successful by default. The character set of the tags will not be checked.

#### URI

- URI format

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

- Parameter description

  Parameter | Mandatory | Type | Description
  --- | --- | --- | ---
  project_id | Yes | String | Project ID See Obtaining a Project ID.
  resource_type | Yes | String | Resource type The value can be the following: smn_topic: topic

  resource_id

  Yes

  String

  Resource ID

  Obtain a resource ID:
  - 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.

#### Request

- Parameter description

  Parameter | Mandatory | Type | Description
  --- | --- | --- | ---
  tags | Yes | Resource_tag structure array | 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 | Operation to be performed, which can be create or delete

  Table 1 Resource_tag structure
  Parameter | Mandatory | Type | Description | Constraint
  --- | --- | --- | --- | ---
  key | Yes | String | Tag key | The key contains 36 Unicode characters at most and cannot be blank or an empty string. It can contain only digits, letters, hyphens (-), and underscores (_) and must not start or end with a space.
  value | Yes | String | Tag value | Each value contains 43 Unicode characters at most and can be an empty string. It can contain only digits, letters, hyphens (-), and underscores (_) and must not start or end with a space.

- Request example

      POST https://{SMN_Endpoint}/v2/{project_id}/{resource_type}/{resource_id}/tags/action

- Request body
  Request body when action is set to create

      {
          "action": "create",
          "tags": [
              {
                  "key": "key1",
                  "value": "value1"
              },
              {
                  "key": "key",
                  "value": "value3"
              }
          ]
      }

  Request body when action is set to delete

      {
          "action": "delete",
          "tags": [
              {
                   "key": "key1"
               },
              {
                  "key": "key2",
                  "value": "value3"
              }
          ]
      }

#### Response

None

#### Returned Value

See Returned Value.

#### Error Code

See section Error Code.

Parent topic: Resource Tag Operations