# Public Cloud › Storage › Object Storage › Lifecycle Management API

> Part of the OVHcloud developer hub. Index of every page and section: https://developers.eu.ovhcloud.com/llms.txt
> The Public Cloud product's sections: https://developers.eu.ovhcloud.com/reference/public-cloud/llms.txt
> Everything in one file: https://developers.eu.ovhcloud.com/llms-full.txt

> 2 operations of the OVHcloud API. Calls carry `authorization: Bearer $OVH_TOKEN`; the EU host is shown, Canada and the United States answer on api.ca.ovhcloud.com and api.us.ovhcloud.com.

Page: https://developers.eu.ovhcloud.com/reference/public-cloud/storage/object-storage/lifecycle-management/

OpenAPI v1: https://api.eu.ovhcloud.com/1.0/__schemas/developer-hub-navigation/public-cloud/storage/object-storage/lifecycle-management.json?format=openapi3
OpenAPI v2: https://api.eu.ovhcloud.com/v2/__schemas/developer-hub-navigation/public-cloud/storage/object-storage/lifecycle-management.json?format=openapi3

## Operations

- `GET /publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle` — List lifecycle rules
- `PUT /publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle` — Replace lifecycle rules

## List lifecycle rules

`GET /v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle`

Link: https://developers.eu.ovhcloud.com/reference/public-cloud/storage/object-storage/lifecycle-management/#getBucketLifecycle

**Status:** Alpha version  
**IAM actions:** `publicCloudProject:apiovh:storage/object/bucket/lifecycle/get`

Returns the rules that expire objects or move them to another storage class.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `bucketName` | path | string | yes | Bucket name |
| `projectId` | path | string | yes | Project ID |

### Responses

| Status | Type | Description |
| --- | --- | --- |
| 200 | publicCloud.storage.object.LifecycleRulesResponse | successful operation |
| 409 | object | Error 409 response |

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `rules` | publicCloud.storage.object.LifecycleRule[] | read-only | Array of lifecycle rules |
| `rules[].abortIncompleteMultipartUpload` | publicCloud.storage.object.LifecycleRuleAbortIncompleteMultipartUpload |  | Settings for aborting incomplete multipart uploads |
| `rules[].abortIncompleteMultipartUpload.daysAfterInitiation` | integer | yes | Number of days after initiation to abort incomplete multipart uploads |
| `rules[].expiration` | publicCloud.storage.object.LifecycleRuleExpiration |  | Expiration settings for current version objects |
| `rules[].expiration.date` | string (date) |  | Date when objects expire |
| `rules[].expiration.days` | integer |  | Number of days after creation when objects expire |
| `rules[].expiration.expiredObjectDeleteMarker` | boolean |  | Whether to remove expired object delete markers |
| `rules[].filter` | publicCloud.storage.object.LifecycleRuleFilter |  | Filter criteria for the rule |
| `rules[].filter.objectSizeGreaterThan` | integer |  | Minimum object size in bytes for the rule to apply |
| `rules[].filter.objectSizeLessThan` | integer |  | Maximum object size in bytes for the rule to apply |
| `rules[].filter.prefix` | string |  | Key prefix to filter objects |
| `rules[].filter.tags` | object |  | Key-value tag pairs to filter objects |
| `rules[].id` | string | yes | Unique identifier of the lifecycle rule |
| `rules[].noncurrentVersionExpiration` | publicCloud.storage.object.LifecycleRuleNoncurrentVersionExpiration |  | Expiration settings for noncurrent version objects |
| `rules[].noncurrentVersionExpiration.newerNoncurrentVersions` | integer |  | Number of newer noncurrent versions to retain |
| `rules[].noncurrentVersionExpiration.noncurrentDays` | integer | yes | Number of days after an object version becomes noncurrent before it expires |
| `rules[].noncurrentVersionTransitions` | publicCloud.storage.object.LifecycleRuleNoncurrentVersionTransition[] |  | Transition rules for noncurrent version objects |
| `rules[].noncurrentVersionTransitions[].newerNoncurrentVersions` | integer |  | Number of newer noncurrent versions to retain before transitioning |
| `rules[].noncurrentVersionTransitions[].noncurrentDays` | integer | yes | Number of days after an object version becomes noncurrent before it transitions |
| `rules[].noncurrentVersionTransitions[].storageClass` | publicCloud.storage.object.StorageClassEnum | yes | Target storage class for the transition — one of `DEEP_ARCHIVE`, `GLACIER_IR`, `HIGH_PERF`, `STANDARD`, `STANDARD_IA` |
| `rules[].status` | publicCloud.storage.object.LifecycleRuleStatusEnum | yes | Whether the rule is enabled or disabled — one of `DISABLED`, `ENABLED` |
| `rules[].transitions` | publicCloud.storage.object.LifecycleRuleTransition[] |  | Transition rules for current version objects |
| `rules[].transitions[].date` | string (date) |  | Date (YYYY-MM-DD) when objects transition to another storage class |
| `rules[].transitions[].days` | integer |  | Number of days after creation when objects transition |
| `rules[].transitions[].storageClass` | publicCloud.storage.object.StorageClassLifecycleEnum | yes | Target storage class for the transition — one of `DEEP_ARCHIVE`, `GLACIER_IR`, `STANDARD`, `STANDARD_IA` |

```json
{
  "rules": [
    {
      "abortIncompleteMultipartUpload": {
        "daysAfterInitiation": 0
      },
      "expiration": {
        "date": "2024-01-01",
        "days": 0,
        "expiredObjectDeleteMarker": true
      },
      "filter": {
        "objectSizeGreaterThan": 0,
        "objectSizeLessThan": 0,
        "prefix": "string",
        "tags": {
          "key": "string"
        }
      },
      "id": "string",
      "noncurrentVersionExpiration": {
        "newerNoncurrentVersions": 0,
        "noncurrentDays": 0
      },
      "noncurrentVersionTransitions": [
        {
          "newerNoncurrentVersions": 0,
          "noncurrentDays": 0,
          "storageClass": "DEEP_ARCHIVE"
        }
      ],
      "status": "DISABLED",
      "transitions": [
        {
          "date": "2024-01-01",
          "days": 0,
          "storageClass": "DEEP_ARCHIVE"
        }
      ]
    }
  ]
}
```

### Example

```bash
curl -X GET \
  "https://api.eu.ovhcloud.com/v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle" \
  -H "accept: application/json" \
  -H "authorization: Bearer $OVH_TOKEN"
```

```python
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh

# Instantiate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
client = ovh.Client(
	endpoint='ovh-eu',               # Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
	application_key='xxxxxxxxxx',    # Application Key
	application_secret='xxxxxxxxxx', # Application Secret
	consumer_key='xxxxxxxxxx',       # Consumer Key
)

result = client.get("/v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle")

# Pretty print
print(json.dumps(result, indent=4))
```

```php
<?php
/**
 * First, download the latest release of PHP wrapper on github
 * And include this script into the folder with extracted files
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

/**
 * Instantiate an OVH Client.
 * You can generate new credentials with full access to your account on
 * the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
 */
$ovh = new Api('xxxxxxxxxx',  // Application Key
               'xxxxxxxxxx',  // Application Secret
               'ovh-eu',      // Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
               'xxxxxxxxxx'); // Consumer Key

$result = $ovh->get("/v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle");

print_r($result);
?>
```

## Replace lifecycle rules

`PUT /v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle`

Link: https://developers.eu.ovhcloud.com/reference/public-cloud/storage/object-storage/lifecycle-management/#editBucketLifecycle

**Status:** Alpha version  
**IAM actions:** `publicCloudProject:apiovh:storage/object/bucket/lifecycle/edit`

Replaces all lifecycle rules of the bucket. An empty list deletes all rules.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `bucketName` | path | string | yes | Bucket name |
| `projectId` | path | string | yes | Project ID |

### Request body (required)

Type: `publicCloud.storage.object.LifecycleRulePut`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `rules` | publicCloud.storage.object.LifecycleRule[] | yes | Array of lifecycle rules. An empty array deletes all rules. |
| `rules[].abortIncompleteMultipartUpload` | publicCloud.storage.object.LifecycleRuleAbortIncompleteMultipartUpload |  | Settings for aborting incomplete multipart uploads |
| `rules[].abortIncompleteMultipartUpload.daysAfterInitiation` | integer | yes | Number of days after initiation to abort incomplete multipart uploads |
| `rules[].expiration` | publicCloud.storage.object.LifecycleRuleExpiration |  | Expiration settings for current version objects |
| `rules[].expiration.date` | string (date) |  | Date when objects expire |
| `rules[].expiration.days` | integer |  | Number of days after creation when objects expire |
| `rules[].expiration.expiredObjectDeleteMarker` | boolean |  | Whether to remove expired object delete markers |
| `rules[].filter` | publicCloud.storage.object.LifecycleRuleFilter |  | Filter criteria for the rule |
| `rules[].filter.objectSizeGreaterThan` | integer |  | Minimum object size in bytes for the rule to apply |
| `rules[].filter.objectSizeLessThan` | integer |  | Maximum object size in bytes for the rule to apply |
| `rules[].filter.prefix` | string |  | Key prefix to filter objects |
| `rules[].filter.tags` | object |  | Key-value tag pairs to filter objects |
| `rules[].id` | string | yes | Unique identifier of the lifecycle rule |
| `rules[].noncurrentVersionExpiration` | publicCloud.storage.object.LifecycleRuleNoncurrentVersionExpiration |  | Expiration settings for noncurrent version objects |
| `rules[].noncurrentVersionExpiration.newerNoncurrentVersions` | integer |  | Number of newer noncurrent versions to retain |
| `rules[].noncurrentVersionExpiration.noncurrentDays` | integer | yes | Number of days after an object version becomes noncurrent before it expires |
| `rules[].noncurrentVersionTransitions` | publicCloud.storage.object.LifecycleRuleNoncurrentVersionTransition[] |  | Transition rules for noncurrent version objects |
| `rules[].noncurrentVersionTransitions[].newerNoncurrentVersions` | integer |  | Number of newer noncurrent versions to retain before transitioning |
| `rules[].noncurrentVersionTransitions[].noncurrentDays` | integer | yes | Number of days after an object version becomes noncurrent before it transitions |
| `rules[].noncurrentVersionTransitions[].storageClass` | publicCloud.storage.object.StorageClassEnum | yes | Target storage class for the transition — one of `DEEP_ARCHIVE`, `GLACIER_IR`, `HIGH_PERF`, `STANDARD`, `STANDARD_IA` |
| `rules[].status` | publicCloud.storage.object.LifecycleRuleStatusEnum | yes | Whether the rule is enabled or disabled — one of `DISABLED`, `ENABLED` |
| `rules[].transitions` | publicCloud.storage.object.LifecycleRuleTransition[] |  | Transition rules for current version objects |
| `rules[].transitions[].date` | string (date) |  | Date (YYYY-MM-DD) when objects transition to another storage class |
| `rules[].transitions[].days` | integer |  | Number of days after creation when objects transition |
| `rules[].transitions[].storageClass` | publicCloud.storage.object.StorageClassLifecycleEnum | yes | Target storage class for the transition — one of `DEEP_ARCHIVE`, `GLACIER_IR`, `STANDARD`, `STANDARD_IA` |

```json
{
  "rules": [
    {
      "abortIncompleteMultipartUpload": {
        "daysAfterInitiation": 0
      },
      "expiration": {
        "date": "2024-01-01",
        "days": 0,
        "expiredObjectDeleteMarker": true
      },
      "filter": {
        "objectSizeGreaterThan": 0,
        "objectSizeLessThan": 0,
        "prefix": "string",
        "tags": {
          "key": "string"
        }
      },
      "id": "string",
      "noncurrentVersionExpiration": {
        "newerNoncurrentVersions": 0,
        "noncurrentDays": 0
      },
      "noncurrentVersionTransitions": [
        {
          "newerNoncurrentVersions": 0,
          "noncurrentDays": 0,
          "storageClass": "DEEP_ARCHIVE"
        }
      ],
      "status": "DISABLED",
      "transitions": [
        {
          "date": "2024-01-01",
          "days": 0,
          "storageClass": "DEEP_ARCHIVE"
        }
      ]
    }
  ]
}
```

### Responses

| Status | Type | Description |
| --- | --- | --- |
| 200 | publicCloud.storage.object.LifecycleRulesResponse | successful operation |
| 409 | object | Error 409 response |

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `rules` | publicCloud.storage.object.LifecycleRule[] | read-only | Array of lifecycle rules |
| `rules[].abortIncompleteMultipartUpload` | publicCloud.storage.object.LifecycleRuleAbortIncompleteMultipartUpload |  | Settings for aborting incomplete multipart uploads |
| `rules[].abortIncompleteMultipartUpload.daysAfterInitiation` | integer | yes | Number of days after initiation to abort incomplete multipart uploads |
| `rules[].expiration` | publicCloud.storage.object.LifecycleRuleExpiration |  | Expiration settings for current version objects |
| `rules[].expiration.date` | string (date) |  | Date when objects expire |
| `rules[].expiration.days` | integer |  | Number of days after creation when objects expire |
| `rules[].expiration.expiredObjectDeleteMarker` | boolean |  | Whether to remove expired object delete markers |
| `rules[].filter` | publicCloud.storage.object.LifecycleRuleFilter |  | Filter criteria for the rule |
| `rules[].filter.objectSizeGreaterThan` | integer |  | Minimum object size in bytes for the rule to apply |
| `rules[].filter.objectSizeLessThan` | integer |  | Maximum object size in bytes for the rule to apply |
| `rules[].filter.prefix` | string |  | Key prefix to filter objects |
| `rules[].filter.tags` | object |  | Key-value tag pairs to filter objects |
| `rules[].id` | string | yes | Unique identifier of the lifecycle rule |
| `rules[].noncurrentVersionExpiration` | publicCloud.storage.object.LifecycleRuleNoncurrentVersionExpiration |  | Expiration settings for noncurrent version objects |
| `rules[].noncurrentVersionExpiration.newerNoncurrentVersions` | integer |  | Number of newer noncurrent versions to retain |
| `rules[].noncurrentVersionExpiration.noncurrentDays` | integer | yes | Number of days after an object version becomes noncurrent before it expires |
| `rules[].noncurrentVersionTransitions` | publicCloud.storage.object.LifecycleRuleNoncurrentVersionTransition[] |  | Transition rules for noncurrent version objects |
| `rules[].noncurrentVersionTransitions[].newerNoncurrentVersions` | integer |  | Number of newer noncurrent versions to retain before transitioning |
| `rules[].noncurrentVersionTransitions[].noncurrentDays` | integer | yes | Number of days after an object version becomes noncurrent before it transitions |
| `rules[].noncurrentVersionTransitions[].storageClass` | publicCloud.storage.object.StorageClassEnum | yes | Target storage class for the transition — one of `DEEP_ARCHIVE`, `GLACIER_IR`, `HIGH_PERF`, `STANDARD`, `STANDARD_IA` |
| `rules[].status` | publicCloud.storage.object.LifecycleRuleStatusEnum | yes | Whether the rule is enabled or disabled — one of `DISABLED`, `ENABLED` |
| `rules[].transitions` | publicCloud.storage.object.LifecycleRuleTransition[] |  | Transition rules for current version objects |
| `rules[].transitions[].date` | string (date) |  | Date (YYYY-MM-DD) when objects transition to another storage class |
| `rules[].transitions[].days` | integer |  | Number of days after creation when objects transition |
| `rules[].transitions[].storageClass` | publicCloud.storage.object.StorageClassLifecycleEnum | yes | Target storage class for the transition — one of `DEEP_ARCHIVE`, `GLACIER_IR`, `STANDARD`, `STANDARD_IA` |

```json
{
  "rules": [
    {
      "abortIncompleteMultipartUpload": {
        "daysAfterInitiation": 0
      },
      "expiration": {
        "date": "2024-01-01",
        "days": 0,
        "expiredObjectDeleteMarker": true
      },
      "filter": {
        "objectSizeGreaterThan": 0,
        "objectSizeLessThan": 0,
        "prefix": "string",
        "tags": {
          "key": "string"
        }
      },
      "id": "string",
      "noncurrentVersionExpiration": {
        "newerNoncurrentVersions": 0,
        "noncurrentDays": 0
      },
      "noncurrentVersionTransitions": [
        {
          "newerNoncurrentVersions": 0,
          "noncurrentDays": 0,
          "storageClass": "DEEP_ARCHIVE"
        }
      ],
      "status": "DISABLED",
      "transitions": [
        {
          "date": "2024-01-01",
          "days": 0,
          "storageClass": "DEEP_ARCHIVE"
        }
      ]
    }
  ]
}
```

### Example

```bash
curl -X PUT \
  "https://api.eu.ovhcloud.com/v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle" \
  -H "accept: application/json" \
  -H "authorization: Bearer $OVH_TOKEN" \
  -H "content-type: application/json" \
  -d '{ }'
```

```python
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh

# Instantiate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
client = ovh.Client(
	endpoint='ovh-eu',               # Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
	application_key='xxxxxxxxxx',    # Application Key
	application_secret='xxxxxxxxxx', # Application Secret
	consumer_key='xxxxxxxxxx',       # Consumer Key
)

# Request body type: publicCloud.storage.object.LifecycleRulePut
result = client.put("/v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle",
	rules = None, # Array of lifecycle rules. An empty array deletes all rules. (type: array)
)

# Pretty print
print(json.dumps(result, indent=4))
```

```php
<?php
/**
 * First, download the latest release of PHP wrapper on github
 * And include this script into the folder with extracted files
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

/**
 * Instantiate an OVH Client.
 * You can generate new credentials with full access to your account on
 * the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
 */
$ovh = new Api('xxxxxxxxxx',  // Application Key
               'xxxxxxxxxx',  // Application Secret
               'ovh-eu',      // Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
               'xxxxxxxxxx'); // Consumer Key

// Request body type: publicCloud.storage.object.LifecycleRulePut
$result = $ovh->put("/v2/publicCloud/project/{projectId}/storage/object/bucket/{bucketName}/lifecycle", array(
	rules => null, // Array of lifecycle rules. An empty array deletes all rules. (type: array)
));

print_r($result);
?>
```
