# Set lifecycle rules for a bucket

```
PUT https://mgmt.storage.dev/v1/providers/:provider_id/orgs/:org_id/buckets/:bucket_name/lifecycle
```

Sets lifecycle rules for automatic object transitions and expiration. If lifecycle rules already exist, they will be completely replaced with the new configuration.

## Lifecycle Rules Overview

Lifecycle rules allow you to automatically:

- **Transition** objects to cheaper storage classes after a specified time
- **Expire** (permanently delete) objects after a specified time

## Examples

### Archive old logs and delete after 1 year

```json
{
  "rules": [
    {
      "id": "archive-and-cleanup-logs",
      "enabled": true,
      "transitions": [
        { "days": 90, "storage_class": "GLACIER" }
      ],
      "expiration": { "days": 365 }
    }
  ]
}
```

## Request

### Path Parameters

**provider_id** string required

Provider ID

**org_id** string required

Organization ID

**bucket_name** string required

Bucket name

### Body **required**

**rules** object[] required

List of lifecycle rules to apply to the bucket.

Array [

**id** string required

Unique identifier for the rule (max 255 chars). Use a descriptive name like `archive-old-logs` or `expire-temp-uploads`.

**enabled** boolean required

Whether the rule is currently active. Set to `false` to temporarily disable a rule without deleting it. When disabled, objects will not be transitioned or expired by this rule.

**expiration** object

Configuration for automatic object deletion (expiration).

## Specify ONE Condition (Not Both)

- `days`: Delete objects N days after their creation date
- `date`: Delete all matching objects on a specific date

**days** integer

Number of days after object creation when the object will be deleted.

**date** date-time

Specific date (at midnight UTC) when all matching objects will be deleted, regardless of when they were created.

**transitions** object[]

List of storage class transitions. Objects will transition through each defined step.

Array [

**days** integer

Number of days after object creation when the transition occurs.

**date** date-time

Specific date (at midnight UTC) when all matching objects will be transitioned, regardless of when they were created.

**storage_class** StorageClass required

Storage class for the bucket. Default is `STANDARD`.

**Possible values:** [`STANDARD`, `STANDARD_IA`, `GLACIER`, `GLACIER_IR`]

**filter** object

Optional scope for a lifecycle rule. When unset, the rule applies to every object in the bucket.

**prefix** string

Only apply this rule to objects whose keys start with the given prefix.

```json
{
  "rules": [
    {
      "id": "string",
      "enabled": true,
      "expiration": {
        "days": 0,
        "date": "2025-01-01T00:00:00Z"
      },
      "transitions": [
        {
          "days": 0,
          "date": "2025-06-01T00:00:00Z",
          "storage_class": "STANDARD"
        }
      ],
      "filter": {
        "prefix": "string"
      }
    }
  ]
}
```

## Responses

- 200
  
  OK

- default

Unexpected error

```json
{
  "message": "string"
}
```

#### Authorization: X-Tigris-Signature

```plaintext
name: X-Tigris-Signature
type: apiKey
in: header
description: HMAC-SHA256 of the canonical request signed using the signing key.
```

```plaintext
name: X-Tigris-Nonce
type: apiKey
in: header
description: Random unique string to identify the request and prevent replay attacks.
```

```plaintext
name: X-Tigris-Time
type: apiKey
in: header
description: Unix timestamp in milliseconds of the request.
```

```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Put, "https://mgmt.storage.dev/v1/providers/:provider_id/orgs/:org_id/buckets/:bucket_name/lifecycle");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("X-Tigris-Signature", "<X-Tigris-Signature>");
request.Headers.Add("X-Tigris-Nonce", "<X-Tigris-Nonce>");
request.Headers.Add("X-Tigris-Time", "<X-Tigris-Time>");
var content = new StringContent("{\n  \"rules\": [\n    {\n      \"id\": \"string\",\n      \"enabled\": true,\n      \"expiration\": {\n        \"days\": 0,\n        \"date\": \"2025-01-01T00:00:00Z\"\n      },\n      \"transitions\": [\n        {\n          \"days\": 0,\n          \"date\": \"2025-06-01T00:00:00Z\",\n          \"storage_class\": \"STANDARD\"\n        }\n      ],\n      \"filter\": {\n        \"prefix\": \"string\"\n      }\n    }\n  ]\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```
