Updated on 2026-07-27 GMT+08:00

Adding Object Tags

Function

OBS allows you to use object tags to classify objects in a bucket. You can call this API to add or update tags for an existing object. For more information about object tags, see Adding Tags to an Object.

Constraints

  • Object tags are now in open beta testing, and you can use them for free. Once the testing period is over, you will be billed for using object tags.
  • To read or write object tags, you must be the object owner or have required permissions. Such permissions can be granted using bucket policies.
  • During cross-region replication, tags of source objects are not copied.
  • Tags cannot be added to files in parallel file systems.
  • Currently, object tags cannot be used in IAM permissions or bucket policies.
  • An object can have up to 10 tags.
  • Constraints on the tag key and value:

    A tag key is case sensitive and must be unique. It cannot be left blank or exceed 128 characters. The following characters are not allowed: ,/|<>=*\

    A tag value is case sensitive and can be left blank. It cannot exceed 255 characters. The following characters are not allowed: ,/|<>=*\

Authorization

To call this API, you must be the object owner or have the permissions to add object tags. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.

  • If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
    • If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you must have the obs:object:PutObjectTagging (versioning disabled) and obs:object:PutObjectVersionTagging (versioning enabled or suspended) permissions. For details, see Creating a Custom IAM Policy.
    • If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you must have the obs:object:putObjectTagging (versioning disabled) and obs:object:putObjectVersionTagging (versioning enabled or suspended) permissions, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.

      Action

      Access Level

      Resource Type (*: Required)

      Condition Key

      Alias

      Dependencies

      obs:object:putObjectTagging (versioning disabled)

      obs:object:putObjectVersionTagging (versioning enabled or suspended)

      Tagging

      object *

      -

      -

      -

  • If you use bucket policies for authorization, you must have the obs:object:PutObjectTagging (versioning disabled) and obs:object:PutObjectVersionTagging (versioning enabled or suspended) permissions. For details, see Creating a Custom Bucket Policy.

URI

PUT /{object_key}?tagging

Calling Method

For details, see Calling APIs. Before calling this API, calculate the API signature and add it to the request.

You can debug this API in API Explorer.

Request Syntax

PUT /objectname?tagging&versionId=versionid HTTP/1.1
Date: date
Authorization: authorization string
Content-MD5: md5
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <TagSet>
        <Tag>
            <Key>Key</Key>
            <Value>Value</Value>
        </Tag>
     </TagSet> 
</Tagging>

URI Parameters

This request contains the headers described in Table 1.

Table 1 URI parameters

Parameter

Mandatory

Type

Description

tagging

Yes

String

Definition

An identifier that marks this request as related to object tagging.

Constraints

N/A

Range

N/A

Default Value

N/A

versionId

No

String

Definition

Version ID of the object to be tagged. The corresponding response header is x-obs-version-id. If the specified version is a delete marker, OBS returns 404 Not Found.

Constraints

N/A

Range

A string of 32 characters

Default Value

N/A

Request Headers

This request contains the headers described in Table 2.

Table 2 Request headers

Header

Mandatory

Type

Description

Content-MD5

Yes

String

Definition

Base64-encoded 128-bit MD5 digest of the message according to RFC 1864. You can also configure the Content-SHA256 header whose value is the Base64-encoded SHA-256 digest of the message. Configure either Content-MD5 or Content-SHA256.

Example: n58IG6hfM7vqI4K0vnWpog==

Constraints

N/A

Range

Base64-encoded MD5 digest

Default Value

N/A

Request Body

In this request body, you need to configure the object tags in XML. Table 3 describes the tag elements to be configured.

Table 3 Object tag elements

Header

Mandatory

Type

Description

Tagging

Yes

Container

Definition

Root element for TagSet and Tag.

Constraints

XML payloads cannot exceed 50 KB.

Range

N/A

Default Value

N/A

TagSet

Yes

Container

Definition

Container element for tags. Tagging is the parent element of TagSet.

Constraints

N/A

Range

N/A

Default Value

N/A

Tag

Yes

Container

Definition

Element for a specific tag. TagSet is the parent element of Tag.

Constraints

A maximum of 10 tags can be added for an object.

Range

N/A

Default Value

N/A

Key

Yes

String

Definition

Key of a tag. Tag is the parent element of Key.

Constraints

A tag key is case-sensitive, must be unique, and cannot be empty. A tag key or a value cannot contain commas (,), asterisks (*), vertical bars (|), slashes (/), less-than signs (<), greater-than signs (>), equal signs (=), backslashes (\), or ASCII control characters (0x00 to 0x1F). It must be URL encoded before being sent to a server. Its length cannot exceed 128 characters.

Range

N/A

Default Value

N/A

Value

Yes

String

Definition

Value of the tag. Tag is the parent element of Value.

Constraints

A tag value is case-sensitive and can be an empty string. A tag key or a value cannot contain commas (,), asterisks (*), vertical bars (|), slashes (/), less-than signs (<), greater-than signs (>), equal signs (=), backslashes (\), or ASCII control characters (0x00 to 0x1F). It must be URL encoded before being sent to a server. Its length cannot exceed 255 characters.

Range

N/A

Default Value

N/A

Response Syntax

1
2
3
4
5
HTTP/1.1 status_code
x-obs-request-id: request id
x-obs-id-2: id
Content-Length: length
Date: date

Response Headers

This response uses common headers. For details, see Table 1.

Response Body

This response contains no elements.

Error Responses

In addition to common error codes, this API also returns some special error codes. Table 4 lists the special error codes and their possible causes.

Table 4 Special errors for adding object tags

Error Code

Description

HTTP Status Code

InvalidTag

The provided object tag was invalid.

400

BadRequest

The number of object tags exceeded the upper limit.

400

MalformedXML

The XML file was malformed.

400

EntityTooLarge

The request body was too long.

400

AccessDenied

No permission to configure object tags.

403

MethodNotAllowed

Method not allowed, because the corresponding feature was not enabled.

405

Sample Request

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
PUT /objectname?tagging&versionId=G001018455096CE600005306000000DD HTTP/1.1
User-Agent: curl/7.29.0
Accept: */*
Date: Wed, 27 Jun 2018 13:22:50 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:Pf1ZyGvVYg2BzOjokZ/BAeR1mEQ=
Content-SHA256: ogX9qClMrVJUBiUSIKDFM0qO41jJM0I5SCN55/OtMyI=
Content-MD5: MnAEvkfQIGnBpchOE2U6Og==
Content-Length: 182
  <TagSet>
    <Tag>
      <Key>TagName1</Key>
      <Value>TagSetValue1</Value>
    </Tag>
  </TagSet>
</Tagging>

Sample Response

1
2
3
4
5
HTTP/1.1 200 OK
Server: OBS
x-obs-request-id: BF26000001643FEBA09B1ED46932CD07
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSEZp87iEirC6DggPB5cN49pSvHBWClg
Date: Wed, 27 Jun 2018 13:22:50 GMT

Using SDKs to Call APIs

You are advised to use OBS SDKs to call APIs. SDKs encapsulate APIs to simplify development. You can call SDK API functions to access OBS without manually calculating signatures.

Helpful Links