Help Center/ Object Storage Service/ API Reference/ Bucket APIs/ Versioning/ Configuring Versioning for a Bucket
Updated on 2026-05-26 GMT+08:00

Configuring Versioning for a Bucket

Function

Versioning provides a way to restore objects that are overwritten or deleted by mistake. You can use versioning to save, query, and restore objects of different versions. Versioning allows you to easily restore lost data due to misoperations or program faults. Versioning can also be used for retaining and archiving data. You can call this API to enable or suspend versioning for a bucket. For more information about versioning, see Versioning.

Authorization

To call this API, you must be the bucket owner or have the permission to configure versioning for a bucket. 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:bucket:PutBucketVersioning permission. 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:bucket:putBucketVersioning permission, 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:bucket:putBucketVersioning

      Write

      bucket *

      -

      -

      -

      • obs:EpochTime
      • obs:SourceIp
      • obs:TlsVersion
      • obs:CustomDomain
  • If you use bucket policies for authorization, you must have the obs:bucket:PutBucketVersioning permission. For details, see Creating a Custom Bucket Policy.

URI

PUT /

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

1
2
3
4
5
6
7
8
9
PUT /?versioning HTTP/1.1 
Host: bucketname.obs.region.myhuaweicloud.com 
Date: date
Authorization: authorization
Content-Length: length

<VersioningConfiguration> 
    <Status>status</Status> 
</VersioningConfiguration>

URI Parameters

This request contains no URI parameters.

Request Headers

This request uses common headers. For details, see Table 3.

Request Body

This request contains elements to configure the bucket versioning in XML format. Table 1 lists the request elements.

Table 1 Elements for configuring bucket versioning

Parameter

Type

Mandatory

Description

VersioningConfiguration

XML

Yes

Definition

Root node of versioning configuration, which is the parent node of Status.

Constraints

N/A

Status

String

Yes

Definition

Versioning status of the bucket.

Constraints

N/A

Range

  • Enabled: Versioning is enabled.
  • Suspended: Versioning is suspended.

Default Value

N/A

Response Syntax

1
2
3
4
HTTP/1.1 status_code
Date: date

Content-Length: length

Response Headers

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

Response Body

This response does not contain a response body.

Error Responses

No special errors. You can find all errors in Table 2.

Sample Request

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
PUT /?versioning HTTP/1.1
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Accept: */*
Date: WED, 01 Jul 2015 03:14:18 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:sc2PM13Wlfcoc/YZLK0MwsI2Zpo=
Content-Length: 89

<VersioningConfiguration>     
    <Status>Enabled</Status> 
</VersioningConfiguration>

Sample Response

1
2
3
4
5
6
HTTP/1.1 200 OK
Server: OBS
x-obs-request-id: BF26000001643672B973EEBC5FBBF909
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSH6rPRHjQCa62fcNpCCPs7+1Aq/hKzE
Date: WED, 01 Jul 2015 03:14:18 GMT
Content-Length: 0

Sample Request: Suspending Versioning

PUT /?versioning HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: WED, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
 
<VersioningConfiguration>
    <Status>Suspended</Status>
</VersioningConfiguration>

Sample Response: Suspending Versioning

x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSjqfl2JttwovZb7kTM+xkyQQyhNyOOC
x-obs-request-id: 0000018A2C044BC6D24722440C5EC81C
Server: OBS
Content-Length: 0
Date: WED, 01 Jul 2015 02:37:22 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

  • For more information about versioning, see Versioning.
  • For details about the billing items involved in API operations, see Billing Items.