Installation
Install and configure the Pushary server SDK for your backend
Installation
npm install @pushary/server
# or
yarn add @pushary/server
# or
pnpm add @pushary/server
# or
bun add @pushary/serverQuick Start
import { createPusharyServer } from '@pushary/server'
const pushary = createPusharyServer({
apiKey: process.env.PUSHARY_API_KEY!,
})
await pushary.notifications.send({
title: 'Hello!',
body: 'Your order has shipped',
subscriberIds: ['sub_123'],
})Configuration
interface PusharyConfig {
apiKey: string // Required: Full API key (pk_xxx.sk_xxx)
baseUrl?: string // Optional: Custom API URL
}API Key
The server SDK requires your full API key which includes the secret portion:
pk_abc123def456.sk_secret789xyzImportant: Never expose this key in client-side code, public repositories, or browser environment variables.
Get your API key from your Dashboard Settings.
Environment Variables
Store your API key securely:
# .env
PUSHARY_API_KEY=pk_xxx.sk_xxxconst pushary = createPusharyServer({
apiKey: process.env.PUSHARY_API_KEY!,
})Error Handling
All methods throw on error. Handle errors appropriately:
try {
await pushary.notifications.send({
title: 'Hello',
body: 'World',
subscriberIds: ['sub_123'],
})
} catch (error) {
if (error instanceof Error) {
console.error('Failed to send:', error.message)
}
}TypeScript
The SDK is fully typed. Import types as needed:
import {
createPusharyServer,
type PusharyServer,
type Subscriber,
type Campaign,
type Template,
type SendNotification,
type SendResult,
} from '@pushary/server'