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

Obtaining Object Tags

Function

This API is used to obtain the tags of an object.

If there is no object version ID (indicated by versionId) contained in the request, you must have the GetObjectTagging permission. If there is an object version ID (indicated by versionId) contained in the request, you must have both the GetObjectTagging and GetObjectVersionTagging permissions. By default, only the object owner can perform this operation. The object owner can grant this permission to others by using a bucket or user policy.

OBS returns the tags of the current object version by default. You can use the versionId parameter to retrieve tags of any other version. If the version is a delete marker, OBS returns 404 Not Found.

Restrictions

  • To obtain the tags of an object, you must be the bucket owner or have the required permissions (obs:object:GetObjectTagging (versioning disabled) and obs:object:GetObjectVersionTagging (versioning enabled or suspended) granted using IAM or obs:object:GetObjectTagging (versioning disabled) and obs:object:GetObjectVersionTagging (versioning enabled or suspended) granted using a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
  • The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
  • This API is not available for parallel file systems.

Method

ObsClient.getObjectTagging(params)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

Bucket

String

Yes

Explanation:

Bucket name

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain a period (.) and a hyphen (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets with the same name in the same region, no error will be reported and the bucket properties comply with those set in the first creation request.

Default value:

None

Key

String

Yes

Explanation:

Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name.

For example, if the address for accessing the object is examplebucket.obs.ap-southeast-1.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

VersionId

String

No

Explanation:

Object version ID

Value range:

The value must contain 32 characters.

Default value:

None

Responses

Table 2 ICommonMsg

Parameter

Type

Description

Status

Number

Explanation:

HTTP status code returned by the OBS server

Value range:

A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For details, see Status Codes.

Code

String

Explanation:

Error code returned by the OBS server

Message

String

Explanation:

Error description returned by the OBS server

HostId

String

Explanation:

Request server ID returned by the OBS server

RequestId

String

Explanation:

Request ID returned by the OBS server

Id2

String

Explanation:

Request ID2 returned by the OBS server

Indicator

String

Explanation:

Error code details returned by the OBS server

Table 3 InterfaceResult

Parameter

Type

Description

Tags

Array

Explanation:

Tag list, for example, [{ Key: 'key1', Value: 'value1' }, { Key: 'key2', Value: 'value2' }]

Sample Code

This example obtains tags of object objectname.

// Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK before storing them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables. Before running the code in this example, configure environment variables AccessKeyID and SecretAccessKey.
// The front-end code does not have the process environment variable, so you need to use a module bundler like webpack to define the process variable.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
const AK = process.env.AccessKeyID
const SK = process.env.SecretAccessKey
// (Optional) If you use a temporary AK and SK pair and a security token to access OBS, obtain them using environment variables.
const security_token= process.env.SecurityToken
// Set server to the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
const server = "https://obs.ap-southeast-1.myhuaweicloud.com"

// Create an ObsClient instance.
var obsClient = new ObsClient({
    access_key_id: AK,
    secret_access_key: SK,
    server: server
});

async function getObjectTagging() {
    try {
        const params = {
            Bucket: 'examplebucket',
            Key: 'objectname',
            // Specify an object version when versioning is enabled.
            // VersionId: '',
        };
        // Obtain object tags.
        const result = await obsClient.getObjectTagging(params);
        if (result.CommonMsg.Status <= 300) {
            console.log("Get object(%s)'s tagging successful!", params.Key);
            console.log("Tags", result.InterfaceResult.Tags);
            console.log("RequestId: %s", result.CommonMsg.RequestId);
            return;
        };
        console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
        console.log("Status: %d", result.CommonMsg.Status);
        console.log("Code: %s", result.CommonMsg.Code);
        console.log("Message: %s", result.CommonMsg.Message);
        console.log("RequestId: %s", result.CommonMsg.RequestId);
    } catch (error) {
        console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
        console.log(error);
    };
};

getObjectTagging()