Skip to main content
For dashboard-based migrations, see Migrating Content.

Automated syncing with Write API

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.
For automated or frequent syncing, use the Write API:

Basic sync script

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:
// 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' };
}
The Write API requires account-level enablement. Contact support@buttercms.com to enable it.