Back to blog
Tutorial15 April 2026

Integrating OnePush API with Node.js and Express

Wire OnePush into Express with fetch, env-based sk_ keys, send routes, and track events. No fake SDK.

Integrating OnePush API with Node.js and Express

Integrating OnePush API with Node.js and Express

This walkthrough wires OnePush into an Express app with environment-based secret keys, a send route, and basic error handling. No fake SDK surface: plain fetch against https://api.onepush.app.

Prerequisites

  • Node 18+ (native fetch)
  • An OnePush secret key (sk_) from the dashboard
  • A verified sending domain
  • A Starter ($20/month) or higher plan with API access (pricing)

Project setup

npm init -y
npm install express dotenv
ONEPUSH_SECRET_KEY=sk_xxxxxxxxxxxx
PORT=3000

Minimal server

import 'dotenv/config';
import express from 'express';

const app = express();
app.use(express.json());

const ONEPUSH_API = 'https://api.onepush.app/v1';

async function sendEmail({ to, subject, body, from }) {
  const response = await fetch(`${ONEPUSH_API}/send`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.ONEPUSH_SECRET_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ to, subject, body, from }),
  });

  const text = await response.text();
  let data;
  try {
    data = text ? JSON.parse(text) : {};
  } catch {
    data = { raw: text };
  }

  if (!response.ok) {
    const error = new Error('OnePush send failed');
    error.status = response.status;
    error.data = data;
    throw error;
  }

  return data;
}

app.post('/api/send-welcome', async (req, res) => {
  try {
    const { email, name } = req.body;
    if (!email) {
      return res.status(400).json({ error: 'email required' });
    }

    const result = await sendEmail({
      to: email,
      subject: 'Welcome',
      body: `<p>Hi ${name || 'there'}, thanks for signing up.</p>`,
    });

    res.json({ ok: true, result });
  } catch (err) {
    console.error(err.data || err);
    res.status(err.status || 500).json({ error: 'send_failed', detail: err.data });
  }
});

app.listen(process.env.PORT, () => {
  console.log(`listening on ${process.env.PORT}`);
});

Track events from the same app

For automations, call /v1/track with a public or secret key when a user signs up:

await fetch('https://api.onepush.app/v1/track', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ONEPUSH_PUBLIC_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    event: 'signup',
    email: 'user@example.com',
    data: {
      first_name: { value: 'Alex', persistent: true },
    },
  }),
});

Error handling that saves you time

  • Surface OnePush status codes to your logs
  • Retry only on 429 and 5xx with backoff
  • Do not retry hard validation errors
  • Keep the secret key server-side only