Skip to content
Pickcell
Menu

Quickstart

From API key to first webhook

Five steps: create a key, exchange it for a token, call the API, register an endpoint and check the signature on what it receives.

  1. 1Create an API key

    In the console, open Identity & Access and then API keys. Only the account owner can create a key. Name it after the system that will use it and give it roles for the products it will call; a key can only carry roles you hold yourself.

    The key is shown once, when you create it. Copy it straight into your server's secret store.

    You also need your account address, the web address your account is served on. The console shows it as the Account address under Apps, Settings, Web addresses.

  2. 2Exchange the key for a token

    Using the SDK? Install it first. It needs Node 18 or later.

    Install
    npm i @pickcell/sdk

    An API key is not sent on ordinary calls. Your server posts it to the key exchange, with your account address in the x-original-host header, and gets back a short-lived access token. Give the SDK the key and your account address and it does this for you.

    curl -X POST https://api.pickcell.io/v1/auth/key-exchange \
      -H "content-type: application/json" \
      -H "x-original-host: <your account address>" \
      -d '{"key": "<your API key>"}'
    const res = await fetch('https://api.pickcell.io/v1/auth/key-exchange', {
      method: 'POST',
      headers: {
        'content-type': 'application/json',
        'x-original-host': process.env.PICKCELL_ACCOUNT_ADDRESS,
      },
      body: JSON.stringify({ key: process.env.PICKCELL_API_KEY }),
    });
    if (!res.ok) throw new Error(`key exchange failed: ${res.status}`);
    const { accessToken } = await res.json();
    import { Pickcell } from '@pickcell/sdk/pickcell';
    
    // The client exchanges the key on its first call, and again
    // when the token is within a minute of expiring.
    const pickcell = new Pickcell({
      baseUrl: 'https://api.pickcell.io',
      apiKey: process.env.PICKCELL_API_KEY,
      accountIdentifier: process.env.PICKCELL_ACCOUNT_ADDRESS, // sent as x-original-host
    });
    200 OK
    { "accessToken": "eyJhbGciOi..." }

    A key and address that do not match answer 401, and a key on an account that is not active answers 403. There is no refresh token: when the token expires, exchange the key again (the SDK renews it for you). Keep the exchange on your server; never ship the key to a browser or app.

  3. 3Make your first call

    Send the token as a bearer token; the SDK sends it for you. This call lists your messaging credit balances and changes nothing, so it is a safe first try. It needs a key with a Messaging role.

    curl https://api.pickcell.io/v1/messaging/balances \
      -H "Authorization: Bearer $PICKCELL_TOKEN"
    const res = await fetch('https://api.pickcell.io/v1/messaging/balances', {
      headers: { Authorization: `Bearer ${accessToken}` },
    });
    const { balances } = await res.json();
    const balances = await pickcell.balances.list();

    The balances come back under balances, with pagination beside them. From here, the Messaging API guide sends your first SMS.

  4. 4Register a webhook endpoint

    Every product publishes its events to one application in your account, Pickcell events. To receive them, add your endpoint to it in the console: open Webhooks, then Applications engine, then Pickcell events, and add an endpoint on its Endpoints tab. The first visit shows an onboarding prompt; complete it and the application is there.

    • Leave the endpoint's allow list empty to receive every event type, or list only the types you want, such as message.delivered. A type missing from a non-empty allow list is never sent to that endpoint.
    • Creating the endpoint shows its signing secret once. Copy it to your receiver before you close the dialog; if you lose it, rotate the secret.

    Each delivery is a JSON POST like this one:

    {
      "id": "<event id>",
      "attemptId": "<attempt id>",
      "attemptNo": 1,
      "eventType": "message.delivered",
      "idempotencyKey": "<idempotency key>",
      "occurredAt": "2026-11-23T01:02:03.000Z",
      "data": {
        "messageId": "<message id>",
        "channel": "SMS",
        "status": "DELIVERED",
        "receiver": "+61400000000",
        "campaignId": null,
        "occurredAt": "2026-11-23T01:02:03.000Z",
        "createdAt": "2026-11-23T01:01:58.000Z"
      }
    }

    A retry carries the same id with a new attemptId, so use id to skip an event you have already handled. Any 2xx response counts as delivered; failed deliveries are retried. The webhooks guide covers filters, retries, replay and ordering.

  5. 5Verify the signature

    Every delivery carries an X-Pickcell-Signature header shaped t=<unix seconds>,v1=<hex>. The signature is an HMAC-SHA256, hex encoded, of the timestamp, a full stop and the raw request body, keyed with your endpoint's secret.

    • Verify the exact bytes you received, before any JSON parsing. A re-serialised body will not match.
    • While a secret is being rotated the header carries more than one v1= value. Accept the delivery if any of them matches.
    • Reject a timestamp outside your replay window. Five minutes is the window we use in our own verifier.
    import { createHmac, timingSafeEqual } from 'node:crypto';
    
    // header: the X-Pickcell-Signature value, e.g. "t=1763859723,v1=5f2b..."
    export function verifyPickcellSignature(rawBody, header, secret, toleranceSeconds = 300) {
      const parts = header.split(',').map((p) => p.trim().split('='));
      const t = Number(parts.find(([k]) => k === 't')?.[1]);
      const signatures = parts.filter(([k]) => k === 'v1').map(([, v]) => v);
      if (!Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
    
      const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
      return signatures.some(
        (s) => s.length === expected.length && timingSafeEqual(Buffer.from(s), Buffer.from(expected)),
      );
    }
    
    // A handler on any runtime with the Fetch API Request and Response.
    export async function POST(request) {
      const rawBody = await request.text(); // the exact bytes, before any JSON parsing
      const header = request.headers.get('x-pickcell-signature') ?? '';
      if (!verifyPickcellSignature(rawBody, header, process.env.PICKCELL_WEBHOOK_SECRET)) {
        return new Response('invalid signature', { status: 400 });
      }
      const event = JSON.parse(rawBody);
      // event.eventType tells you what happened; event.data carries the details.
      return new Response(null, { status: 204 });
    }
    import { verifyWebhookSignature } from '@pickcell/sdk/outsend';
    
    // A handler on any runtime with the Fetch API Request and Response.
    export async function POST(request: Request) {
      const rawBody = await request.text(); // the exact bytes, before any JSON parsing
      // Accepts a Headers instance; pass [newSecret, oldSecret] while rotating.
      // The replay window defaults to five minutes.
      if (!verifyWebhookSignature(rawBody, request.headers, process.env.PICKCELL_WEBHOOK_SECRET!)) {
        return new Response('invalid signature', { status: 400 });
      }
      const event = JSON.parse(rawBody);
      // event.eventType tells you what happened; event.data carries the details.
      return new Response(null, { status: 204 });
    }

    Next, see rotating a secret and the events each product sends, starting from the webhooks guide.

Ready to build?

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