• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js SDK)
  4. Bucket-Related APIs
  5. GET Buckets

GET Buckets

API Description

You can use this API to obtain the bucket list. In the list, bucket names are displayed in lexicographical order.

Method Definition

ObsClient.listBuckets(callback)

Request Parameter

None

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Buckets

Object

Bucket list information

  

Bucket

Array

Bucket list

  

BucketName

String

Bucket name

CreationDate

String

Creation time of the bucket

Owner

Object

Bucket owner

  

ID

String

ID of the domain to which the bucket owner belongs

Name

String

Name of the bucket owner

Sample Code

obsClient.listBuckets((err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('Owner:');
                     console.log('ID-->' + result.InterfaceResult.Owner.ID);
                     console.log('Name-->' + result.InterfaceResult.Owner.Name);
                     console.log('Buckets:');
                     for(let i=0;i<result.InterfaceResult.Buckets.Bucket.length;i++){
                           console.log('Bucket[' + i + ']:');
                           console.log('BucketName-->' + result.InterfaceResult.Buckets.Bucket[i].BucketName);
                           console.log('CreationDate-->' + result.InterfaceResult.Buckets.Bucket[i].CreationDate);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});