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

# Automating cross-site sync

> Use the Write API to programmatically sync content between sites and environments.

<Info>
  For dashboard-based migrations, see [Migrating Content](../../create-content/multi-site-environments/migrating-content).
</Info>

## Automated syncing with Write API

<Info>
  **When to use Write API vs Migrations:**

  * **Migrations tool:** Best for one-time or infrequent bulk content transfers between environments. Handled by the ButterCMS support team through the dashboard.
  * **Write API:** Best for automated, programmatic, or frequent content syncing. Requires development work but gives you full control over what, when, and how content is synced.
</Info>

For automated or frequent syncing, use the Write API:

### Basic sync script

```javascript theme={null}
const Butter = require('buttercms');

// Source and destination sites
const sourceButter = Butter('source-site-write-token');
const destButter = Butter('dest-site-write-token');

async function syncCollection(collectionSlug) {
  // Fetch from source
  const { data } = await sourceButter.content.retrieve([collectionSlug]);
  const items = data.data[collectionSlug];

  // Push to destination
  for (const item of items) {
    await destButter.content.createCollectionItem(collectionSlug, item);
  }

  console.log(`Synced ${items.length} items to ${collectionSlug}`);
}

// Sync authors collection
syncCollection('authors');
```

### Scheduled sync

Set up automated syncing with cron jobs or serverless functions:

```javascript theme={null}
// AWS Lambda / Vercel Serverless Function
export async function handler(event) {
  const sourceButter = Butter(process.env.SOURCE_WRITE_TOKEN);
  const destButter = Butter(process.env.DEST_WRITE_TOKEN);

  // Fetch recently updated content
  const { data } = await sourceButter.page.list('*', {
    page_size: 100,
    order: '-updated'
  });

  // Sync to destination
  for (const page of data.data) {
    await destButter.page.create(page.page_type, page.fields);
  }

  return { statusCode: 200, body: 'Sync complete' };
}
```

<Info>
  The Write API requires account-level enablement. Contact [support@buttercms.com](mailto:support@buttercms.com) to enable it.
</Info>
