Feature Overview
This document provides an overview of APIs and SDK code samples for COS inventory.
API | Operation | Description |
Setting an inventory job | Sets an inventory job for a bucket | |
Querying Inventory Jobs | Queries the inventory jobs of a bucket | |
Deleting an Inventory Job | Deletes an inventory job from a bucket |
SDK API References
Setting an inventory job
Note
This API (PUT Bucket inventory) is used to create an inventory job for a bucket.
Sample code
// Bucket name in the format ofBucketName-APPID(APPIDis required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.String bucket = "examplebucket-1250000000";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 inventoryputBucketInventoryRequest.setIncludedObjectVersions(InventoryConfiguration.IncludedObjectVersions.ALL);// Backup frequencyputBucketInventoryRequest.setScheduleFrequency(InventoryConfiguration.SCHEDULE_FREQUENCY_DAILY);// Backup pathputBucketInventoryRequest.setDestination("CSV", "1000000000","examplebucket-1250000000", "region", "dir/");cosXmlService.putBucketInventoryAsync(putBucketInventoryRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {PutBucketInventoryResult putBucketInventoryResult =(PutBucketInventoryResult) result;}// If you are using Kotlin to call the API, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called, i.e.:// Is the type of clientException CosXmlClientException? Is the type of serviceException CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Note
Error codes
The following describes some common errors that may occur when making requests using this API.
Error Codes | 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
Note
This API is used to query the inventory jobs of a bucket.
Sample code
// Bucket name in the format ofBucketName-APPID(APPIDis required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.String bucket = "examplebucket-1250000000";GetBucketInventoryRequest getBucketInventoryRequest =new GetBucketInventoryRequest(bucket);getBucketInventoryRequest.setInventoryId("exampleInventoryId");cosXmlService.getBucketInventoryAsync(getBucketInventoryRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketInventoryResult getBucketInventoryResult =(GetBucketInventoryResult) result;}// If you are using Kotlin to call the API, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called, i.e.:// Is the type of clientException CosXmlClientException? Is the type of serviceException CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Note
Deleting an Inventory Job
Note
This API is used to delete an inventory job from a bucket.
Sample code
// Bucket name in the format ofBucketName-APPID(APPIDis required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.String bucket = "examplebucket-1250000000";DeleteBucketInventoryRequest deleteBucketInventoryRequest =new DeleteBucketInventoryRequest(bucket);deleteBucketInventoryRequest.setInventoryId("exampleInventoryId");cosXmlService.deleteBucketInventoryAsync(deleteBucketInventoryRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {DeleteBucketInventoryResult deleteBucketInventoryResult =(DeleteBucketInventoryResult) result;}// If you are using Kotlin to call the API, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called, i.e.:// Is the type of clientException CosXmlClientException? Is the type of serviceException CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {}});
Note