PUT Bucket tagging

Last updated: 2021-07-27 16:00:43

    Overview

    COS supports setting tags for existing buckets. This API is used to set key-value pairs for a bucket as tags, helping you manage existing bucket resources and costs.

    Note:

    Currently, you can set up to 50 different tags for a single bucket.

    You are advised to use API Explorer.
    Debug
    API Explorer makes it easy to make online API calls, verify signatures, generate SDK code, search for APIs, etc. You can also use it to query the content of each request as well as its response.

    Request

    Sample request

    PUT /?tagging HTTP 1.1
    Host:<BucketName-APPID>.cos.<Region>.myqcloud.com
    Date: GMT Date
    Authorization: Auth String
    Content-MD5: MD5
    Content-Length: Content Length
    Content-Type: application/xml
    [Request Body]
    
    Note:

    Authorization: Auth String (See Request Signature for details.)

    Request headers

    This API only uses common request headers. For more information, please see Common Request Headers.

    Request body

    For this request, you need to configure the following set of tags:

    <?xml version="1.0" encoding="UTF-8" ?>
    <Tagging>
      <TagSet>
          <Tag>
              <Key>age</Key>
              <Value>18</Value>
          </Tag>
          <Tag>
              <Key>name</Key>
              <Value>xiaoming</Value>
          </Tag>
      </TagSet>
    </Tagging>
    

    The nodes are described as follows:

    Node Name (Keyword) Parent Node Description Type Required
    Tagging None Tag set Container Yes
    TagSet Tagging Tag set Container Yes
    Tag Tagging.TagSet Tag set, which can contain up to 50 tags Containers Yes
    Key Tagging.TagSet.Tag Tag key, which can contain up to 128 characters. A tag key can contain English letters, digits, spaces, plus signs, minus signs, underscores, equals signs, dots, colons, and slashes String Yes
    Value Tagging.TagSet.Tag Tag value, which can contain up to 256 characters. A tag value can contain English letters, digits, spaces, plus signs, minus signs, underscores, equals signs, dots, colons, and slashes String Yes

    Response

    Response headers

    This API returns only common response headers. For more information, please see Common Response Headers.

    Response body

    The response body is empty.

    Error codes

    This API returns common error responses and error codes. For more information, please see Error Codes.

    Sample

    Request

    The following request writes two tags "{age:18}" and "{name:xiaoming}" to the bucket examplebucket-1250000000. COS successfully configured the tags and returns 204 (success).

    PUT /?tagging HTTP/1.1
    User-Agent: curl/7.29.0
    Accept: */*
    Host: examplebucket-1250000000.cos.ap-chengdu.myqcloud.com
    Authorization: q-sign-algorithm=sha1&q-ak=AKIDrbAYjEBqqdEconpFi8NPFsOjrnX4****&q-sign-time=1516361923;1517361973&q-key-time=1516361923;1517361973&q-url-param-list=tagging&q-header-list=content-md5;host&q-signature=71251feb4501494edcfbd01747fa87300375****
    Content-MD5: LIbd5t5HLPhuNWYkP6qHcQ==
    Content-Length: 127
    Content-Type: application/xml
    
    <Tagging>
      <TagSet>
          <Tag>
              <Key>age</Key>
              <Value>18</Value>
          </Tag>
          <Tag>
              <Key>name</Key>
              <Value>xiaoming</Value>
          </Tag>
      </TagSet>
    </Tagging>
    

    Response

    HTTP/1.1 204 No Content
    Content-Type: application/xml
    Content-Length: 0
    Connection: keep-alive
    Date: Fri, 19 Jan 2018 11:40:22 GMT
    Server: tencent-cos
    x-cos-request-id: NWE2MWQ5MjZfMTBhYzM1MGFfMTA5ODVfMTVj****