Skip to content
Pickcell
Menu

Messaging API

Send SMS and email from your own code

Send SMS and email from your own systems, run campaigns, keep addresses off your sends and hear about delivery through signed webhooks.

Key concepts

Channel
Every send and campaign names one, SMS or EMAIL.
Sender
Who the message comes from. It must be a verified sender for the channel - an alpha tag or phone number for SMS, an email address for email. Add senders in the console.
Gateway
The provider that carries the message. Leave gatewayId out and your account's default enabled gateway for the channel is used.
Template
A message you design in the console. Send it by templateId and fill its {{merge fields}} with variables.
Category
Messages are COMMERCIAL unless you mark them TRANSACTIONAL, as you would a receipt.
Suppression
An address that must not be messaged on a channel. A send to it is refused with 422.

Every call below needs a bearer token from your API key - see the quickstart. Messages are paid from prepaid credit; see pricing.

Each task shows curl, fetch and the SDK (npm i @pickcell/sdk). The SDK examples use one client, made with your API key and account address; it exchanges the key for a token itself:

import { Pickcell } from '@pickcell/sdk/pickcell';

const pickcell = new Pickcell({
  baseUrl: 'https://api.pickcell.io',
  apiKey: process.env.PICKCELL_API_KEY,
  accountIdentifier: process.env.PICKCELL_ACCOUNT_ADDRESS,
});

Send an SMS

Name the channel, the recipient, a verified sender and the text. The send is dispatched straight away and the response is 201 with the new message under messages, including its id and status.

curl -X POST https://api.pickcell.io/v1/messaging/messages \
  -H "Authorization: Bearer $PICKCELL_TOKEN" \
  -H "content-type: application/json" \
  -H "Idempotency-Key: order-1042-shipped" \
  -d '{
    "channel": "SMS",
    "receiver": "+61400000000",
    "sender": "ACME",
    "content": { "textBody": "Your order 1042 is on its way." }
  }'
const res = await fetch('https://api.pickcell.io/v1/messaging/messages', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${accessToken}`,
    'content-type': 'application/json',
    'Idempotency-Key': 'order-1042-shipped',
  },
  body: JSON.stringify({
    channel: 'SMS',
    receiver: '+61400000000',
    sender: 'ACME',
    content: { textBody: 'Your order 1042 is on its way.' },
  }),
});
const { messages: message } = await res.json();
const message = await pickcell.messages.send({
  channel: 'SMS',
  receiver: '+61400000000',
  sender: 'ACME',
  content: { textBody: 'Your order 1042 is on its way.' },
  idempotencyKey: 'order-1042-shipped', // sent as the Idempotency-Key header
});

The Idempotency-Key header is optional and makes a retry safe. Repeat the same key with the same body and you get the first response back instead of a second message, for 24 hours. The same key with a different body answers 409, and a repeat while the first call is still running answers 429 with Retry-After.

To send later, add scheduledAt as an ISO 8601 date-time with an offset. It must be in the future.

Send an email from a template

Send exactly one of content, templateId or templateVersionId. With a template, variables fills its merge fields.

curl -X POST https://api.pickcell.io/v1/messaging/messages \
  -H "Authorization: Bearer $PICKCELL_TOKEN" \
  -H "content-type: application/json" \
  -d '{
    "channel": "EMAIL",
    "receiver": "sam@example.com",
    "sender": "hello@acme.example",
    "templateId": "<template id>",
    "variables": { "firstName": "Sam", "orderCode": "1042" },
    "category": "TRANSACTIONAL"
  }'
const res = await fetch('https://api.pickcell.io/v1/messaging/messages', {
  method: 'POST',
  headers: { Authorization: `Bearer ${accessToken}`, 'content-type': 'application/json' },
  body: JSON.stringify({
    channel: 'EMAIL',
    receiver: 'sam@example.com',
    sender: 'hello@acme.example',
    templateId: '<template id>',
    variables: { firstName: 'Sam', orderCode: '1042' },
    category: 'TRANSACTIONAL',
  }),
});
const { messages: message } = await res.json();
const message = await pickcell.messages.send({
  channel: 'EMAIL',
  receiver: 'sam@example.com',
  sender: 'hello@acme.example',
  templateId: '<template id>',
  variables: { firstName: 'Sam', orderCode: '1042' },
  category: 'TRANSACTIONAL',
});

An email without a template takes content with a subject and an htmlBody.

Check a message

curl https://api.pickcell.io/v1/messaging/messages/<message id> \
  -H "Authorization: Bearer $PICKCELL_TOKEN"
const res = await fetch(`https://api.pickcell.io/v1/messaging/messages/${messageId}`, {
  headers: { Authorization: `Bearer ${accessToken}` },
});
const { messages: message } = await res.json();
const message = await pickcell.messages.get(messageId);

The message comes back under messages. Its status moves on as the gateway reports back, for example QUEUED, SENT_TO_GATEWAY, DELIVERED or BOUNCED. New statuses are added over time, so treat one you do not know as “not handled yet” rather than an error. To be told instead of asking, subscribe to the events below.

Send a campaign to your own list

A campaign sends one message to many people. Pass the rows inline, say which field holds the address, and use any other field as a merge field.

curl -X POST https://api.pickcell.io/v1/messaging/campaigns \
  -H "Authorization: Bearer $PICKCELL_TOKEN" \
  -H "content-type: application/json" \
  -d '{
    "channel": "SMS",
    "sender": "ACME",
    "messageTemplate": { "textBody": "Hi {{name}}, your table is booked for {{time}}." },
    "receivers": {
      "addressField": "phone",
      "rows": [
        { "phone": "+61400000000", "name": "Sam", "time": "7pm" },
        { "phone": "+61400000001", "name": "Alex", "time": "8pm" }
      ]
    }
  }'
const res = await fetch('https://api.pickcell.io/v1/messaging/campaigns', {
  method: 'POST',
  headers: { Authorization: `Bearer ${accessToken}`, 'content-type': 'application/json' },
  body: JSON.stringify({
    channel: 'SMS',
    sender: 'ACME',
    messageTemplate: { textBody: 'Hi {{name}}, your table is booked for {{time}}.' },
    receivers: {
      addressField: 'phone',
      rows: [
        { phone: '+61400000000', name: 'Sam', time: '7pm' },
        { phone: '+61400000001', name: 'Alex', time: '8pm' },
      ],
    },
  }),
});
const { campaigns: campaign } = await res.json();
const campaign = await pickcell.campaigns.create({
  channel: 'SMS',
  sender: 'ACME',
  messageTemplate: { textBody: 'Hi {{name}}, your table is booked for {{time}}.' },
  receivers: {
    addressField: 'phone',
    rows: [
      { phone: '+61400000000', name: 'Sam', time: '7pm' },
      { phone: '+61400000001', name: 'Alex', time: '8pm' },
    ],
  },
});

The response is 201 with the campaign under campaigns. It is queued and sent in the background; read it again with GET /v1/messaging/campaigns/{id} to follow status and the counters such as totalRecipients, sentCount and deliveredCount. Add scheduledAt to send it later. If your plan does not include campaigns, the call answers 402.

Stop messaging an address

Add a suppression and every later send to that address on that channel is refused.

curl -X POST https://api.pickcell.io/v1/messaging/suppressions \
  -H "Authorization: Bearer $PICKCELL_TOKEN" \
  -H "content-type: application/json" \
  -d '{
    "channel": "SMS",
    "address": "+61400000000",
    "reason": "MANUAL_BLOCK",
    "source": "MANUAL"
  }'
const res = await fetch('https://api.pickcell.io/v1/messaging/suppressions', {
  method: 'POST',
  headers: { Authorization: `Bearer ${accessToken}`, 'content-type': 'application/json' },
  body: JSON.stringify({ channel: 'SMS', address: '+61400000000', reason: 'MANUAL_BLOCK', source: 'MANUAL' }),
});
const { suppressions: suppression } = await res.json();
const suppression = await pickcell.suppressions.add({
  channel: 'SMS',
  address: '+61400000000',
  reason: 'MANUAL_BLOCK',
  source: 'MANUAL',
});

An address that is already suppressed on the channel answers 409.

Events

Delivered to the endpoints on your Pickcell events application, wrapped in the delivery envelope. The webhooks guide covers filters, signatures and retries.

  • message.queuedA message was accepted and queued for dispatch.
  • message.sentA message was handed to its delivery gateway.
  • message.deliveredThe gateway confirmed delivery to the recipient's handset or inbox.
  • message.bouncedThe gateway reported a permanent delivery failure (the address bounced).
  • contact.addedA contact was added to a subscriber list; it receives nothing until it completes double opt-in.
  • contact.verifiedA contact completed double opt-in.
  • contact.unsubscribedA contact opted out, for example by replying STOP.
  • contact.deletedA contact was deleted from a list.

Ready to build?

Create an account, then make your first API key in the console.