Campaigns
Create and manage push notification campaigns
Overview
Campaigns allow you to send notifications to multiple subscribers at once. They track delivery statistics and can be scheduled for future delivery.
List Campaigns
const { data } = await pushary.campaigns.list({
limit: 50,
})
for (const campaign of data) {
console.log(campaign.name, campaign.status, campaign.totalSent)
}Create Campaign
const campaign = await pushary.campaigns.create({
name: 'Welcome Campaign',
title: 'Welcome to Our App!',
body: 'Thanks for subscribing. Here\'s what you can expect...',
actionUrl: 'https://example.com/welcome',
iconUrl: 'https://example.com/icon.png',
})Create Options
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Internal campaign name |
title | string | Yes | Notification title |
body | string | Yes | Notification body |
iconUrl | string | No | Notification icon URL |
imageUrl | string | No | Large image URL |
actionUrl | string | No | Click destination URL |
scheduledAt | string | No | ISO date for scheduled send |
segmentId | string | No | Target segment ID |
tags | string[] | No | Target subscribers with tags |
Get Campaign
const campaign = await pushary.campaigns.get('camp_123')
console.log(campaign.status) // 'draft'
console.log(campaign.totalTargeted) // 1500
console.log(campaign.totalClicked) // 0Campaign Object
interface Campaign {
id: string
siteId: string
name: string
title: string
body: string
iconUrl?: string
imageUrl?: string
actionUrl?: string
status: 'draft' | 'scheduled' | 'sending' | 'active' | 'paused' | 'completed' | 'cancelled'
scheduledAt?: string
totalTargeted: number
totalSent: number
totalDelivered: number
totalClicked: number
createdAt: string
}Update Campaign
Modify a draft or scheduled campaign:
const updated = await pushary.campaigns.update('camp_123', {
title: 'Updated Title',
body: 'Updated message body',
})Only draft and scheduled campaigns can be updated.
Send Campaign
Send a draft campaign immediately:
const sent = await pushary.campaigns.send('camp_123')
console.log(sent.status) // 'sending'
console.log(sent.totalTargeted) // 1500The campaign will be queued for delivery. Use stats() to monitor progress.
Pause Campaign
Pause an active campaign:
await pushary.campaigns.pause('camp_123')Resume Campaign
Resume a paused campaign:
await pushary.campaigns.resume('camp_123')Delete Campaign
Delete a campaign:
await pushary.campaigns.delete('camp_123')Only draft and cancelled campaigns can be deleted.
Get Stats
Get delivery statistics for a campaign:
const stats = await pushary.campaigns.stats('camp_123')
console.log(stats.totalSent) // 1500
console.log(stats.totalDelivered) // 1450
console.log(stats.totalClicked) // 145
console.log(stats.deliveryRate) // 96.67
console.log(stats.clickRate) // 10.00Stats Object
interface CampaignStats {
totalSent: number
totalDelivered: number
totalClicked: number
totalFailed: number
deliveryRate: number // Percentage
clickRate: number // Percentage
}Scheduled Campaigns
Schedule a campaign for future delivery:
const campaign = await pushary.campaigns.create({
name: 'Black Friday Sale',
title: '🎉 50% Off Everything!',
body: 'Our biggest sale of the year starts now.',
actionUrl: 'https://example.com/sale',
scheduledAt: '2024-11-29T00:00:00Z',
})The campaign will automatically send at the scheduled time.