Skip to Content
Wapitick developers

Order and shipping updates

Keep customers in the CRM and send order updates with a utility template.

  1. POST /v1/contacts:upsert finds the customer by phone or creates them, so every update lands in one chat.
  2. Send a utility template with the order details. Put your order id in client_ref: sending the same client_ref again returns the first message instead of sending twice.
  3. Follow delivery with message.status_updated webhooks (opt in with +message.status_updated), or read GET /v1/messages/{id}.

cURL

curl.sh
#!/usr/bin/env bash
# Order and shipping updates: contacts_upsert, channels_list, messages_send, messages_get (runs in test mode)
set -euo pipefail
API="${WAPITICK_API_URL:-https://api.wapitick.com}"
AUTH="Authorization: Bearer $WAPITICK_API_KEY"

# Keep the customer in Wapitick (find by phone or create)
curl -sf "$API/v1/contacts:upsert" -H "$AUTH" -H "Content-Type: application/json" -H "Idempotency-Key: ctc-1042" \
  -d '{"match":{"kind":"phone","value":"+15550100001"},"create_if_missing":true,"data":{"name":"Asha","phones":["+15550100001"],"tags":["customer"]}}' >/dev/null
CHANNEL=$(curl -sf "$API/v1/channels" -H "$AUTH" | jq -r '.data[0].id')
# client_ref ties the message to your order: sending the same client_ref twice returns the first message
MSG=$(curl -sf "$API/v1/messages" -H "$AUTH" -H "Content-Type: application/json" -H "Idempotency-Key: order-1042-shipped" \
  -d "{\"channel_id\":\"$CHANNEL\",\"to\":{\"phone\":\"+15550100001\"},\"client_ref\":\"order-1042-shipped\",\"type\":\"template\",\"template\":{\"name\":\"order_update\",\"language\":\"en\",\"components\":[{\"type\":\"body\",\"parameters\":[{\"type\":\"text\",\"text\":\"Asha\"},{\"type\":\"text\",\"text\":\"#1042\"}]}]}}" | jq -r .id)
sleep 3
curl -sf "$API/v1/messages/$MSG" -H "$AUTH" | jq '{id, status}'

Node

node.mjs
// biome-ignore-all lint/suspicious/noConsole: a docs sample prints its result
// Order and shipping updates: contacts_upsert, messages_send, messages_get
import { Wapitick } from "@wapitick/node";

const wapitick = new Wapitick({
  apiKey: process.env.WAPITICK_API_KEY,
  baseUrl: process.env.WAPITICK_API_URL,
});
await wapitick.contacts.upsert({ phone: "+15550100001", name: "Asha", tags: ["customer"] });
const msg = await wapitick.messages.sendTemplate({
  to: "+15550100001",
  name: "order_update",
  variables: ["Asha", "#1042"],
  clientRef: "order-1042-shipped", // the same client_ref twice returns the first message
});
await new Promise((r) => setTimeout(r, 3000));
const now = await wapitick.messages.get(msg.id);
console.log(JSON.stringify({ id: now.id, status: now.status }));

Python

python.py
# Order and shipping updates: contacts_upsert, messages_send, messages_get
import json
import os
import time

from wapitick import Wapitick

w = Wapitick(api_key=os.environ["WAPITICK_API_KEY"], base_url=os.environ.get("WAPITICK_API_URL", "https://api.wapitick.com"))
w.contacts.upsert("+15550100001", name="Asha", tags=["customer"])
msg = w.messages.send_template("+15550100001", "order_update", variables=["Asha", "#1042"], client_ref="order-1042-shipped")
time.sleep(3)
now = w.messages.get(msg["id"])
print(json.dumps({"id": now["id"], "status": now["status"]}))

PHP

php.php
<?php
// Order and shipping updates: contacts_upsert, messages_send, messages_get
require __DIR__ . '/vendor/autoload.php';

$w = new Wapitick\Client(getenv('WAPITICK_API_KEY'), getenv('WAPITICK_API_URL') ?: 'https://api.wapitick.com');
$w->upsertContact('+15550100001', 'Asha', null, ['customer']);
$msg = $w->sendTemplate('+15550100001', 'order_update', 'en', ['Asha', '#1042']);
sleep(3);
$now = $w->call('messages_get', ['message_id' => $msg['id']]);
echo json_encode(['id' => $now['id'], 'status' => $now['status']]), "\n";

Google Apps Script

apps-script.gs
// biome-ignore-all lint/correctness/noUnusedVariables: Apps Script runs these functions by name
// Order updates from a Google Sheet: contacts_upsert, messages_send.
// Sheet columns: A phone (+E.164), B name, C order number, D status (the script writes it).
// Script properties: WAPITICK_API_KEY (wk_test_...), optional WAPITICK_API_URL.
function wapitick_(method, path, body) {
  const props = PropertiesService.getScriptProperties();
  const base = props.getProperty("WAPITICK_API_URL") || "https://api.wapitick.com";
  const res = UrlFetchApp.fetch(base + path, {
    method: method,
    contentType: "application/json",
    headers: {
      Authorization: `Bearer ${props.getProperty("WAPITICK_API_KEY")}`,
      "Idempotency-Key": Utilities.getUuid(),
    },
    payload: body ? JSON.stringify(body) : undefined,
    muteHttpExceptions: true,
  });
  const json = JSON.parse(res.getContentText() || "null");
  if (res.getResponseCode() >= 300) throw new Error(`${json.code}: ${json.detail}`);
  return json;
}

function sendOrderUpdates() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const rows = sheet.getDataRange().getValues();
  const channel = wapitick_("get", "/v1/channels").data[0].id;
  for (let i = 1; i < rows.length; i++) {
    const phone = String(rows[i][0]),
      name = String(rows[i][1]),
      order = String(rows[i][2]);
    if (!phone || rows[i][3]) continue; // skip empty rows and rows already sent
    wapitick_("post", "/v1/contacts:upsert", {
      match: { kind: "phone", value: phone },
      create_if_missing: true,
      data: { name: name, phones: [phone] },
    });
    const msg = wapitick_("post", "/v1/messages", {
      channel_id: channel,
      to: { phone: phone },
      client_ref: `order-${order}`,
      type: "template",
      template: {
        name: "order_update",
        language: "en",
        components: [
          {
            type: "body",
            parameters: [
              { type: "text", text: name },
              { type: "text", text: order },
            ],
          },
        ],
      },
    });
    sheet.getRange(i + 1, 4).setValue(`${msg.status} ${msg.id}`);
  }
}

The Google Apps Script version sends one update per row of a sheet ("send from a sheet") and writes the status back.

Operations: contacts_upsert, channels_list, messages_send, messages_get.

This page as Markdown