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 |
For the parameters and method descriptions of all the APIs in the SDK, see Api Documentation.
This API is used to create an inventory job for a bucket.
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.
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 |
This API is used to query the inventory jobs of a bucket.
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.
This API is used to delete an inventory job from a bucket.
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?