Use this file to discover all available pages before exploring further.
The GatelyCampaigns class gives you full programmatic control over Gately’s email campaign system — create and send campaigns, schedule them, generate content with AI, track stats, and manage attachments.
import { GatelyCampaigns } from '@gately/sdk'const campaigns = new GatelyCampaigns({ projectId: 'YOUR_PROJECT_ID', // apiUrl: 'https://api.usegately.com' // optional override})
GatelyCampaigns works in both browser and Node.js environments. In Node.js it uses GatelyNodeClient internally; in the browser it uses GatelyBrowserClient.
Create and send (or schedule) a campaign in one call.
const result = await campaigns.send({ name: 'June Newsletter', subject: 'What we shipped this month', content: '<h1>June Update</h1><p>Here is what we built...</p>', // Pick one or more recipient sources: recipient_all_contacts: true, // recipient_emails: ['alice@example.com'], // recipient_list_ids: ['list_abc'], // recipient_segment_ids: ['seg_xyz'],})console.log(`Sent to ${result.successful_sends} of ${result.total_recipients}`)
Scheduling — pass scheduled_at to queue for later:
await campaigns.send({ name: 'Product Launch', subject: 'Introducing our new feature!', content: '<p>Check it out.</p>', recipient_list_ids: ['list_abc123'], scheduled_at: '2025-07-01T09:00:00Z',})
Poll a campaign until it reaches a terminal status (sent, partially_sent, or failed). Useful after scheduling.
const result = await campaigns.send({ name: 'Launch', subject: 'We are live!', content: '<p>Check it out.</p>', recipient_all_contacts: true,})// Wait for it to finish sendingconst final = await campaigns.waitForCompletion(result.campaign.id)console.log('Final status:', final.status)console.log('Delivered:', final.delivered_count)
Options:
await campaigns.waitForCompletion( campaignId, 3000, // poll every 3 seconds (default) 120_000 // give up after 2 minutes (default))
interface CampaignStats { sent: number delivered: number opened: number clicked: number bounced: number complained: number // Added by SDK: delivery_rate?: number open_rate?: number click_rate?: number}