Inventory

Last updated: 2020-08-26 11:01:37

    Overview

    This document provides an overview of APIs and SDK code samples related to COS inventory.

    API Operation Description
    PUT Bucket inventory Setting an inventory job Sets an inventory job for a bucket
    GET Bucket inventory Querying inventory jobs Queries the inventory jobs of a bucket
    DELETE Bucket inventory Deleting an inventory job Deletes an inventory job from a bucket

    SDK API Reference

    For the parameters and method descriptions of all the APIs in the SDK, see SDK API Reference.

    Setting an Inventory Job

    API description

    This API is used to create an inventory job for a bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    PutBucketInventoryRequest putBucketInventoryRequest =
            new PutBucketInventoryRequest(bucket);
    putBucketInventoryRequest.setInventoryId("exampleInventoryId");
    // Indicate whether to include object versions in the inventory:
    // If set to All, all object versions are included in the inventory,
    // with additional fields VersionId, IsLatest, and DeleteMarker
    // If set to Current, no object versions are included in the inventory
    putBucketInventoryRequest.setIncludedObjectVersions(InventoryConfiguration
            .IncludedObjectVersions.ALL);
    // Backup frequency
    putBucketInventoryRequest.setScheduleFrequency(InventoryConfiguration
            .SCHEDULE_FREQUENCY_DAILY);
    // Backup path
    putBucketInventoryRequest.setDestination("CSV", "1000000000",
            "examplebucket-1250000000", "region", "dir/");
    
    cosXmlService.putBucketInventoryAsync(putBucketInventoryRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            PutBucketInventoryResult putBucketInventoryResult =
                    (PutBucketInventoryResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
            if (clientException != null) {
                clientException.printStackTrace();
            } else {
                serviceException.printStackTrace();
            }
        }
    });

    Note:

    For more samples, please visit GitHub.

    Error codes

    The following describes some common errors that may occur when making requests using this API.

    Error Code Description Status Code
    InvalidArgument Invalid parameter value HTTP 400 Bad Request
    TooManyConfigurations The number of inventories has reached the upper limit of 1,000 HTTP 400 Bad Request
    AccessDenied Unauthorized access. You may not have access to the bucket HTTP 403 Forbidden

    Querying Inventory Jobs

    API description

    This API is used to query the inventory jobs of a bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    GetBucketInventoryRequest getBucketInventoryRequest =
            new GetBucketInventoryRequest(bucket);
    getBucketInventoryRequest.setInventoryId("exampleInventoryId");
    
    cosXmlService.getBucketInventoryAsync(getBucketInventoryRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            GetBucketInventoryResult getBucketInventoryResult =
                    (GetBucketInventoryResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
            if (clientException != null) {
                clientException.printStackTrace();
            } else {
                serviceException.printStackTrace();
            }
        }
    });

    Note:

    For more samples, please visit GitHub.

    Deleting an Inventory Job

    API description

    This API is used to delete an inventory job from a bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    DeleteBucketInventoryRequest deleteBucketInventoryRequest =
            new DeleteBucketInventoryRequest(bucket);
    deleteBucketInventoryRequest.setInventoryId("exampleInventoryId");
    
    cosXmlService.deleteBucketInventoryAsync(deleteBucketInventoryRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            DeleteBucketInventoryResult deleteBucketInventoryResult =
                    (DeleteBucketInventoryResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
        }
    });

    Note:

    For more samples, please visit GitHub.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help