Integrations / Shopify

Sendersy + Shopify

Shopify + Sendersy: catch webhooks (order/create, customers/create) and send custom emails via Sendersy.

1. Install

bash
# Shopify Admin → Settings → Notifications → Webhooks → Create webhook

2. Environment variables

bash
# Create webhook in Shopify Admin → Notifications → Webhooks
# Format: JSON   Event: order/create   URL: https://yourapp.com/webhooks/shopify

3. Send an email

ts
// Next.js / Express handler for Shopify webhook
import crypto from 'crypto'

const SHOPIFY_SECRET = process.env.SHOPIFY_WEBHOOK_SECRET!
const SENDERSY_KEY   = process.env.SENDERSY_API_KEY!

export async function POST(req: Request) {
  // Verify Shopify HMAC
  const body = await req.text()
  const hmac = req.headers.get('x-shopify-hmac-sha256') ?? ''
  const expected = crypto.createHmac('sha256', SHOPIFY_SECRET).update(body).digest('base64')
  if (hmac !== expected) return new Response('Forbidden', { status: 403 })

  const order = JSON.parse(body)

  // Send Sendersy order-confirmation template
  await fetch('https://api.sendersy.com/v1/emails', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${SENDERSY_KEY}`,
      'Content-Type':  'application/json',
    },
    body: JSON.stringify({
      from: 'Acme Shop <orders@acme.com>',
      to:   order.customer.email,
      template_id: 'order-confirmation',
      variables: {
        name:         order.customer.first_name,
        order_number: order.name,
        order_total:  `$${order.total_price}`,
        tracking_url: `https://acme.com/track/${order.id}`,
      },
    }),
  })

  return new Response('OK')
}

Ready to start?

Get your API key in 30 seconds.

Sign up