Bucket Tags

Last updated: 2023-09-20 11:42:22

Feature Overview

This document provides an overview of APIs and SDK code samples for bucket tagging.
API
Operation
Description
Setting bucket tags
Sets tags for an existing bucket
Querying bucket tags
Queries the existing tags of a specified bucket
Deleting bucket tags
Deletes specified bucket tags

Setting bucket tags

Note

This API (PUT Bucket tagging) is used to set tags for an existing bucket.

Sample Request

cos.putBucketTagging({
Bucket: 'examplebucket-1250000000', /* Required */
Region: 'COS_REGION', /* The region where the bucket is located, required field */
Tagging: {
Tags: [
{"Key": "k1", "Value": "v1"},
{"Key": "k2", "Value": "v2"}
]
}
}, function(err, data) {
console.log(err || data);
});

Description

Parameter name
Description
Local Disk Types
Required
Bucket
Bucket for which the tag is configured in the format: BucketName-APPID
String
Required
Region
Bucket region. For the enumerated values, see Regions and Access Endpoints.
String
Required
Tagging
Tag information
Object
Required
- Tags
Tag information
ObjectArray
Required
- - Key
Tag name
String
Required
- - Value
Tag Value
String
Required

Callback function description

function(err, data) { ... }
Parameter name
Description
Local Disk Types
err
Returns a network or service error when the request fails. If the request is successful, this is empty. For more information, see Error Codes
Object
- statusCode
HTTP status code, such as 200, 403, and 404
Number
- headers
Returned headers
Object
data
Object returned when the request is successful. If the request fails, this parameter is empty.
Object
- statusCode
HTTP status code, such as 200, 403, and 404
Number
- headers
Returned headers
Object

Querying bucket tags

Note

This API (GET Bucket tagging) is used to query the existing tags of a specified bucket.

Sample Request

cos.getBucketTagging({
Bucket: 'examplebucket-1250000000', /* Required */
Region: 'COS_REGION', /* The region where the bucket is located, required field */
}, function(err, data) {
console.log(err || data);
});

Sample response

{
"Tags": [
{"Key": "k1", "Value": "v1"},
{"Key": "k2", "Value": "v2"}
],
"statusCode": 200,
"headers": {}
}

Description

Parameter name
Description
Local Disk Types
Required
Bucket
Bucket for which the bucket policy is queried in the format: BucketName-APPID
String
Required
Region
Bucket region. For the enumerated values, see Regions and Access Endpoints.
String
Required

Callback function description

function(err, data) { ... }
Parameter name
Description
Local Disk Types
err
Returns a network or service error when the request fails. If the request is successful, this is empty. For more information, see Error Codes
Object
- statusCode
HTTP status code, such as 200, 403, and 404
Number
- headers
Returned headers
Object
data
Object returned when the request is successful. If the request fails, this parameter is empty.
Object
- statusCode
HTTP status code, such as 200, 403, and 404
Number
- headers
Returned headers
Object
- Tags
Tag information
ObjectArray
- - Key
Tag name
String
- - Value
Tag Value
String

Deleting bucket tags

Note

This API (DELETE Bucket tagging) is used to delete specified bucket tags.

Sample Request

cos.deleteBucketTagging({
Bucket: 'examplebucket-1250000000', /* Required */
Region: 'COS_REGION', /* The region where the bucket is located, required field */
}, function(err, data) {
console.log(err || data);
});

Description

Parameter name
Description
Local Disk Types
Required
Bucket
Bucket for which the tag is deleted in the format: BucketName-APPID
String
Required
Region
Bucket region. For the enumerated values, see Regions and Access Endpoints.
String
Required

Callback function description

function(err, data) { ... }
Parameter name
Description
Local Disk Types
err
Returns a network or service error when the request fails. If the request is successful, this is empty. For more information, see Error Codes
Object
- statusCode
HTTP status code, such as 200, 403, and 404
Number
- headers
Returned headers
Object
data
Object returned when the request is successful. If the request fails, this parameter is empty.
Object
- statusCode
HTTP status code, such as 200, 403, and 404
Number
- headers
Returned headers
Object