> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zavu.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Retention

> Understanding data retention policies and how to export your data

# Data Retention

Zavu implements configurable data retention policies to help you manage storage and comply with data protection regulations like GDPR.

## Default Retention Period

| Data Type          | Default Retention | Maximum Retention |
| ------------------ | ----------------- | ----------------- |
| Messages           | 90 days           | 180 days          |
| Conversations      | 90 days           | 180 days          |
| Webhook Deliveries | 90 days           | 180 days          |
| Agent Executions   | 90 days           | 180 days          |
| Activities         | 90 days           | 180 days          |

<Warning>
  Data retention is applied retroactively. When you reduce the retention period, existing data older than the new limit will be automatically deleted within 24 hours.
</Warning>

## Configuring Retention

You can configure the retention period for your project through the [Dashboard](https://dashboard.zavu.dev/data-retention) or via the API.

### Dashboard

1. Navigate to **Infrastructure > Data Retention** in the sidebar
2. Use the slider to set your desired retention period (90-180 days)
3. Review the estimated impact on your existing data
4. Click **Save Changes** and confirm

### What's NOT Affected

The following data types are excluded from retention policies due to legal requirements:

* **Billing transactions** - Required for financial records (7 years)
* **MAU charges** - Required for billing reconciliation
* **API Keys** - Not subject to automatic deletion
* **Contacts** - Customer data managed separately

## Data Exports

Before data is deleted, you can export it for your records. Exports are available in JSON format.

### Creating an Export

<CodeGroup>
  ```typescript TypeScript theme={null}
  import Zavudev from '@zavudev/sdk';

  const zavu = new Zavudev();

  // Create an export request
  const { export: exportJob } = await zavu.exports.create({
    dataTypes: ['messages', 'conversations'],
    dateFrom: '2024-01-01T00:00:00Z',
    dateTo: '2024-06-30T23:59:59Z',
  });

  console.log('Export ID:', exportJob.id);
  console.log('Status:', exportJob.status); // 'pending' initially
  ```

  ```python Python theme={null}
  from zavudev import Zavudev

  zavu = Zavudev()

  # Create an export request
  export_job = zavu.exports.create(
      data_types=['messages', 'conversations'],
      date_from='2024-01-01T00:00:00Z',
      date_to='2024-06-30T23:59:59Z',
  )

  print(f"Export ID: {export_job.export.id}")
  print(f"Status: {export_job.export.status}")  # 'pending' initially
  ```

  ```ruby Ruby theme={null}
  require 'zavudev'

  zavu = Zavudev::Client.new

  # Create an export request
  export_job = zavu.exports.create(
    data_types: ['messages', 'conversations'],
    date_from: '2024-01-01T00:00:00Z',
    date_to: '2024-06-30T23:59:59Z'
  )

  puts "Export ID: #{export_job.export.id}"
  puts "Status: #{export_job.export.status}"  # 'pending' initially
  ```

  ```go Go theme={null}
  package main

  import (
      "context"
      "fmt"

      "github.com/zavudev/sdk-go"
  )

  func main() {
      client := zavudev.NewClient()

      // Create an export request
      exportJob, err := client.Exports.Create(context.TODO(), zavudev.ExportCreateParams{
          DataTypes: []string{"messages", "conversations"},
          DateFrom:  zavudev.String("2024-01-01T00:00:00Z"),
          DateTo:    zavudev.String("2024-06-30T23:59:59Z"),
      })

      fmt.Println("Export ID:", exportJob.Export.ID)
      fmt.Println("Status:", exportJob.Export.Status) // 'pending' initially
  }
  ```

  ```php PHP theme={null}
  $zavu = new Zavudev\Client();

  // Create an export request
  $exportJob = $zavu->exports->create([
      'dataTypes' => ['messages', 'conversations'],
      'dateFrom' => '2024-01-01T00:00:00Z',
      'dateTo' => '2024-06-30T23:59:59Z',
  ]);

  echo "Export ID: " . $exportJob->export->id . "\n";
  echo "Status: " . $exportJob->export->status . "\n"; // 'pending' initially
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.zavu.dev/v1/exports \
    -H "Authorization: Bearer $ZAVU_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "dataTypes": ["messages", "conversations"],
      "dateFrom": "2024-01-01T00:00:00Z",
      "dateTo": "2024-06-30T23:59:59Z"
    }'
  ```
</CodeGroup>

### Checking Export Status

Exports are processed asynchronously. Poll the export endpoint to check when it's ready:

<CodeGroup>
  ```typescript TypeScript theme={null}
  // Check export status
  const { export: exportJob } = await zavu.exports.retrieve('exp_abc123');

  if (exportJob.status === 'completed') {
    console.log('Download URL:', exportJob.downloadUrl);
    console.log('File size:', exportJob.fileSize, 'bytes');
  }
  ```

  ```python Python theme={null}
  # Check export status
  export_job = zavu.exports.retrieve('exp_abc123')

  if export_job.export.status == 'completed':
      print(f"Download URL: {export_job.export.download_url}")
      print(f"File size: {export_job.export.file_size} bytes")
  ```

  ```ruby Ruby theme={null}
  # Check export status
  export_job = zavu.exports.retrieve('exp_abc123')

  if export_job.export.status == 'completed'
    puts "Download URL: #{export_job.export.download_url}"
    puts "File size: #{export_job.export.file_size} bytes"
  end
  ```

  ```go Go theme={null}
  // Check export status
  exportJob, err := client.Exports.Retrieve(context.TODO(), "exp_abc123")

  if exportJob.Export.Status == "completed" {
      fmt.Println("Download URL:", exportJob.Export.DownloadURL)
      fmt.Println("File size:", exportJob.Export.FileSize, "bytes")
  }
  ```

  ```php PHP theme={null}
  // Check export status
  $exportJob = $zavu->exports->retrieve('exp_abc123');

  if ($exportJob->export->status === 'completed') {
      echo "Download URL: " . $exportJob->export->downloadUrl . "\n";
      echo "File size: " . $exportJob->export->fileSize . " bytes\n";
  }
  ```

  ```bash cURL theme={null}
  curl https://api.zavu.dev/v1/exports/exp_abc123 \
    -H "Authorization: Bearer $ZAVU_API_KEY"
  ```
</CodeGroup>

### Export Status Values

| Status       | Description                                     |
| ------------ | ----------------------------------------------- |
| `pending`    | Export request received, queued for processing  |
| `processing` | Export is being generated                       |
| `completed`  | Export ready, download URL available            |
| `failed`     | Export failed, check `errorMessage` for details |

<Info>
  Export download links expire after **24 hours**. Make sure to download your export before it expires.
</Info>

## Available Data Types

When creating an export, you can include any combination of these data types:

| Data Type           | Description                             |
| ------------------- | --------------------------------------- |
| `messages`          | All sent and received messages          |
| `conversations`     | Conversation threads with contacts      |
| `webhookDeliveries` | Webhook delivery attempts and responses |
| `agentExecutions`   | AI agent execution logs and responses   |
| `activities`        | Activity logs for your project          |

## Export Format

Exports are provided as JSON files with the following structure:

```json theme={null}
{
  "messages": [
    {
      "_id": "abc123",
      "to": "+14155551234",
      "from": "+15551234567",
      "channel": "sms",
      "messageType": "text",
      "text": "Hello!",
      "status": "delivered",
      "createdAt": 1704067200000
    }
  ],
  "conversations": [
    {
      "_id": "conv123",
      "contactPhone": "+14155551234",
      "lastMessageAt": 1704067200000
    }
  ]
}
```

## GDPR Compliance

Zavu's data retention features help you comply with GDPR requirements:

* **Right to erasure**: Data is automatically deleted after the retention period
* **Data portability**: Export your data at any time in a machine-readable format
* **Storage limitation**: Configure retention periods appropriate for your use case
* **Transparency**: View exactly how much data will be affected before changing settings

<Info>
  For complete data deletion requests from specific users, contact our support team.
</Info>

## Best Practices

1. **Export before reducing retention**: Always export your data before reducing the retention period
2. **Regular backups**: Set up periodic exports of your important data
3. **Monitor expiration**: Track when your exports will expire and download them promptly
4. **Test exports**: Verify your export files can be opened and read correctly

## Related

* [API Reference: Exports](/api-reference/exports)
* [Dashboard: Data Retention](https://dashboard.zavu.dev/data-retention)
