This document provides an overview of APIs and SDK code samples related to inventory.
API | Operation Name | Operation Description |
---|---|---|
PUT Bucket inventory | Setting an inventory job | Sets an inventory job in a bucket |
GET Bucket inventory | Querying inventory jobs | Queries inventory jobs for a bucket |
List Bucket Inventory Configurations | Querying all inventories | Queries all inventory jobs of a bucket |
DELETE Bucket inventory | Deleting an inventory job | Deletes an inventory job of a bucket |
This API (PUT Bucket inventory) is used to create an inventory job in a bucket.
func (s *BucketService) PutInventory(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error)
opt := &cos.BucketPutInventoryOptions{
ID: "test_id",
// True or False
IsEnabled: "True",
IncludedObjectVersions: "All",
Filter: &cos.BucketInventoryFilter{
Prefix: "test",
},
OptionalFields: &cos.BucketInventoryOptionalFields{
BucketInventoryFields: []string{
"Size", "LastModifiedDate",
},
},
Schedule: &cos.BucketInventorySchedule{
// Weekly or Daily
Frequency: "Daily",
},
Destination: &cos.BucketInventoryDestination{
Bucket: dBucket,
Format: "CSV",
},
}
resp, err := client.Bucket.PutInventory(context.Background(), id, opt)
type BucketInventoryFilter struct {
Prefix string
}
type BucketInventoryOptionalFields struct {
BucketInventoryFields []string
}
type BucketInventorySchedule struct {
Frequency string
}
type BucketInventoryEncryption struct {
SSECOS string
}
type BucketInventoryDestination struct {
Bucket string
AccountId string
Prefix string
Format string
Encryption *BucketInventoryEncryption
}
// BucketPutInventoryOptions ...
type BucketPutInventoryOptions struct {
XMLName xml.Name
ID string
IsEnabled string
IncludedObjectVersions string
Filter *BucketInventoryFilter
OptionalFields *BucketInventoryOptionalFields
Schedule *BucketInventorySchedule
Destination *BucketInventoryDestination
}
Parameter Name | Description | Type |
---|---|---|
BucketPutInventoryOptions | Inventory configuration information of bucket | Struct |
ID | Inventory name, corresponding to the ID in the request parameter | String |
IsEnabled | Inventory status flag: true , the inventory is enabled; false , no inventories will be generated |
String |
IncludedObjectVersions | Whether to include object versions in the inventory All , the inventory will include all object versions and add VersionId , IsLatest , and DeleteMarker fields Current , no object version information will be included in the inventory |
String |
Filter | Filter | Struct |
Prefix | Prefix of the objects to be analyzed | String |
OptionalFields | Sets the analysis items that should be included in the inventory result | Struct |
BucketInventoryFields | Name of the analysis items that can be optionally included in the inventory result. Valid values: Size, LastModifiedDate, StorageClass, ETag, IsMultipartUploaded, ReplicationStatus | []String |
Schedule | Inventory job frequency | Struct |
Frequency | Inventory job frequency. Enumerated values: Daily, Weekly | String |
Destination | Describes the information of the inventory result storage | Struct |
Bucket | Name of the bucket where the inventory result is stored | String |
AccountId | Bucket owner ID, such as 100000000001 | String |
Prefix | Prefix of the inventory result | String |
Format | File format of the inventory result. CSV is available | String |
Encryption | Option to provide server-side encryption for the inventory result | Struct |
SSECOS | Uses SSE-COS encryption | String |
Some frequent special errors that may occur with this request are listed below:
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 probably do not have access to the bucket. | HTTP 403 Forbidden |
This API (GET Bucket inventory) is used to query the inventory job information in a bucket.
func (s *BucketService) GetInventory(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error)
v, response, err := client.Bucket.GetInventory(context.Background(), id)
type BucketGetInventoryResult BucketPutInventoryOptions
Parameter Name | Description | Type |
---|---|---|
BucketPutInventoryOptions | Inventory configuration information of bucket | Struct |
ID | Inventory name, corresponding to the ID in the request parameter | String |
IsEnabled | Inventory status flag: true , the inventory is enabled; false , no inventories will be generated |
String |
IncludedObjectVersions | Whether to include object versions in the inventory All , the inventory will include all object versions and add VersionId , IsLatest , and DeleteMarker fields Current , no object version information will be included in the inventory |
String |
Filter | Filter | Struct |
Prefix | Prefix of the objects to be analyzed | String |
OptionalFields | Sets the analysis items that should be included in the inventory result | Struct |
BucketInventoryFields | Name of the analysis items that can be optionally included in the inventory result. Valid values: Size, LastModifiedDate, StorageClass, ETag, IsMultipartUploaded, ReplicationStatus | []String |
Schedule | Inventory job frequency | Struct |
Frequency | Inventory job frequency. Enumerated values: Daily, Weekly | String |
Destination | Describes the information of the inventory result storage | Struct |
Bucket | Name of the bucket where the inventory result is stored | String |
AccountId | Bucket owner ID, such as 100000000001 | String |
Prefix | Prefix of the inventory result | String |
Format | File format of the inventory result. CSV is available | String |
Encryption | Option to provide server-side encryption for the inventory result | Struct |
SSECOS | Uses SSE-COS encryption | String |
This API (List Bucket Inventory Configurations) is used to request that all inventory jobs in a bucket be returned. Up to 1,000 inventory jobs can be configured in one bucket.
func (s *BucketService) ListInventoryConfigurations(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error)
v, resp, err := client.Bucket.ListInventoryConfigurations(context.Background(), "")
type BucketListInventoryConfiguartion BucketPutInventoryOptions
type ListBucketInventoryConfigResult struct {
XMLName xml.Name
InventoryConfigurations []BucketListInventoryConfiguartion
IsTruncated bool
ContinuationToken string
NextContinuationToken string
}
Parameter Name | Description | Type |
---|---|---|
ListBucketInventoryConfigResult | All inventory configuration information of bucket | Struct |
InventoryConfigurations | Inventory configuration information | Struct |
IsTruncated | Flag about whether all inventory jobs have been listed. If yes, it is false ; otherwise, it is true |
Bool |
ContinuationToken | Flag of the inventory list on the current page, which can be understood as the page number. It corresponds to the continuation-token parameter in the request |
String |
NextContinuationToken | Flag of the next page of inventory list. If there is a value in this parameter, the value can be used as the continuation-token parameter to initiate a GET request to get the inventory job information of the next page |
String |
This API (DELETE Bucket inventory) is used to delete a specified inventory job of a bucket.
func (s *BucketService) DeleteInventory(ctx context.Context, id string) (*Response, error)
resp, err = client.Bucket.DeleteInventory(context.Background(), "test_id")
Parameter Name | Description | Type |
---|---|---|
id | Inventory name | String |
Was this page helpful?