Back to Integrations

Klaviyo Integration

Marketing

E-commerce email image optimization

Klaviyo Webhook Integration

Process Product Images for Campaigns
// Klaviyo product sync with enhanced images
async function syncProductWithEnhancedImages(product) {
  // Enhance product image
  const enhanced = await fetch('https://butterflyapi.com/api/v1/run', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_BUTTERFLY_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      api: 'image-enhance',
      input: { image_url: product.image_url, scale: 2 }
    })
  }).then(r => r.json());
  
  // Remove background for clean product shots
  const noBg = await fetch('https://butterflyapi.com/api/v1/run', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_BUTTERFLY_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      api: 'background-remove',
      input: { image_url: enhanced.output.image_url }
    })
  }).then(r => r.json());
  
  // Sync to Klaviyo catalog
  await fetch('https://a.klaviyo.com/api/catalog-items/', {
    method: 'POST',
    headers: {
      'Authorization': 'Klaviyo-API-Key YOUR_KLAVIYO_API_KEY',
      'Content-Type': 'application/json',
      'revision': '2024-02-15'
    },
    body: JSON.stringify({
      data: {
        type: 'catalog-item',
        attributes: {
          external_id: product.id,
          title: product.name,
          image_full_url: enhanced.output.image_url,
          image_thumbnail_url: noBg.output.image_url
        }
      }
    })
  });
}