Inventory

Last updated: 2020-08-31 16:27:07

    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 References

    For the parameters and method descriptions of all the APIs in the SDK, see Api Documentation.

    Setting an Inventory Job

    API description

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

    Sample code

    try
    {
      string inventoryId = "aInventoryId";
      String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
      PutBucketInventoryRequest putRequest = new PutBucketInventoryRequest(bucket, inventoryId);
      putRequest.SetDestination("CSV", "100000000001", "examplebucket-1250000000", "ap-guangzhou","list1");
      putRequest.IsEnable(true);
      putRequest.SetScheduleFrequency("Daily");
      // Execute the request
      PutBucketInventoryResult putResult = cosXml.putBucketInventory(putRequest); 
    
      // Request successful 
      Console.WriteLine(putResult.GetResultInfo());
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
      // Request failed
      Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
      // Request failed
      Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }

    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 most likely do not have access permission for the bucket HTTP 403 Forbidden

    Querying Inventory Jobs

    API description

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

    Sample code

    try
    {
      string inventoryId = "aInventoryId";
      String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
      GetBucketInventoryRequest getRequest = new GetBucketInventoryRequest(bucket);
      getRequest.SetInventoryId(inventoryId);
    
      GetBucketInventoryResult getResult = cosXml.getBucketInventory(getRequest);
    
      InventoryConfiguration configuration = getResult.inventoryConfiguration;
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
      // Request failed
      Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
      // Request failed
      Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }

    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

    try
    {
      string inventoryId = "aInventoryId";
      String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
      DeleteBucketInventoryRequest deleteRequest = new DeleteBucketInventoryRequest(bucket);
      deleteRequest.SetInventoryId(inventoryId);
      DeleteBucketInventoryResult deleteResult = cosXml.deleteBucketInventory(deleteRequest);
    
      // Request successful 
      Console.WriteLine(deleteResult.GetResultInfo());
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
      // Request failed
      Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
      // Request failed
      Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }

    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