Developers · Business API v1

Business API

Connect your store, CRM or billing system to LhamsApp. Send order updates and invoices, and receive your customers' messages via webhook, without exposing their phone numbers.

Leer en español

Introduction

The Business API connects your store, CRM or billing system to LhamsApp: order updates, PDF invoices, replies to your customers and inbound messages via webhook. It's a REST API with JSON over HTTPS.

Base URLhttps://api.lhamsapp.com/api/business/v1
FormatJSON (UTF-8). Files are uploaded as multipart/form-data.
Phone numbersInternational E.164 format: +, country code and number (7 to 15 digits). Spaces, dashes, dots and parentheses are ignored.
RequirementsAn account in business mode with a plan that includes the API (Business or Enterprise).

Only with your customers. The API only works with people who already have a relationship with your business: they messaged you, placed an order or follow you. It can't be used for cold outreach or to find out who uses LhamsApp.

Authentication

Create your API key in the app: Business settingsAPI keys (integrations). The key (it starts with lhamsapp_live_) is shown only once: keep it in a secrets manager, never in browser code or a mobile app.

Send it on every request with the header Authorization: Bearer <key> (recommended) or with X-LhamsApp-Key: <key>.

Shell
export LHAMSAPP_API_KEY="lhamsapp_live_…"
export BASE="https://api.lhamsapp.com/api/business/v1"
curl
curl "$BASE/conversations?limit=20" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY"

Permissions

  • messages — send messages, upload files, list threads and broadcast.
  • contacts — look up and open threads with customers by phone or user_id.

Give each integration only the permissions it needs.

Test keys (sandbox)

With a sandbox key, sends with to validate the whole flow (relationship, privacy, idempotency) but deliver nothing: the response comes back with "status": "accepted" and "sandbox": true.

Limits

LimitValueWhen exceeded
Burst per key120 requests per minute429 rate_limited
Daily and monthly quotaDepends on your plan. Defaults: Business 200/day and 1,000/month; Enterprise 20,000/day with no monthly cap.429 quota_exceeded
Contact lookups100 per hour per key429 rate_limited
BroadcastUp to 500 threads per call (Enterprise plan)422 too_many_recipients
Listingslimit from 1 to 100 (default 50)—

The daily quota resets every day and the monthly one every month; the app shows each key's usage (calls_today and calls_this_month). On a 429 rate_limited, wait the seconds in retry_after or the Retry-After header before retrying, with exponential backoff.

Endpoints

All paths are relative to the base URL.

Method and pathWhat forPermission
POST /messages Send text or a document to a customer, or post in a business thread messages
POST /media Upload a file and get its media_id messages
GET /conversations List your business threads messages
POST /contacts Open the thread with a customer by phone contacts
GET /contacts/by-phone/{phone} Can I reach this number? contacts
GET /contacts/{user_id} A customer's public profile contacts
POST /broadcast Broadcast to many threads (Enterprise plan) messages
GET /stats Business stats —
POST /keys/rotate Rotate the key you're calling with —
POST/messagesmessages

Send a message

Accepts three body shapes:

  • Text to a customer: to, text and, optionally, idempotency_key. Uses (or creates) the business thread with that customer.
  • Document to a customer: to, "type": "document", media_id (from POST /media), filename, caption (up to 1,024 characters) and idempotency_key.
  • In an existing thread: conversation_id, content and, optionally, content_type (text by default). Returns 201.

Idempotency: if you repeat a send with the same idempotency_key (up to 128 characters) to the same customer, it isn't duplicated: you get the original message back with "idempotent": true. Always use it when retrying.

curl · text
curl -X POST "$BASE/messages" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+18095551234",
    "text": "Hi! Your order #1042 is ready for pickup.",
    "idempotency_key": "order-1042-ready"
  }'
Response 200
{
  "data": {
    "id": "6f1c…",
    "status": "sent",
    "conversation_id": "a93e…"
  }
}
curl · in a thread
curl -X POST "$BASE/messages" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "a93e…",
    "content": "Thanks for your purchase 🙌",
    "content_type": "text"
  }'

# 201 → {"data": {"message_id": "…", "conversation_id": "a93e…", "sent_at": "2026-11-02T14:05:09Z"}}
GET/conversations?limit=50messages

List your business threads

Returns your business threads, newest first: id, type, name and updated_at. It never includes the owner's personal chats.

POST/contactscontacts
GET/contacts/by-phone/{phone}contacts
GET/contacts/{user_id}contacts

Contacts

  • POST /contacts with {"phone": "+1809…"} opens or fetches the thread with that customer and returns user_id, customer_id, username, display_name and conversation_id.
  • GET /contacts/by-phone/{phone} returns has_lhamsapp: true only if it's a customer with a relationship with you, not blocked and accepting your messages; in any other case, false.
  • GET /contacts/{user_id} returns the public profile (user_id, customer_id, username, display_name) of a customer you have a relationship with.
curl
# Can I reach this number? (encode + as %2B)
curl "$BASE/contacts/by-phone/%2B18095551234" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY"
# → {"data": {"has_lhamsapp": true}}

# Open (or fetch) the business thread with that customer
curl -X POST "$BASE/contacts" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"phone": "+18095551234"}'
# → {"data": {"user_id": "…", "customer_id": "cus_Q2x…", "username": "maria",
#             "display_name": "maria", "conversation_id": "a93e…"}}
POST/broadcastmessagesEnterprise

Broadcast

Sends the same content to several of your threads (up to 500 per call). Each thread is validated separately and the result reports sent, forbidden or failed for each one.

curl
curl -X POST "$BASE/broadcast" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"conversation_ids": ["a93e…", "c41d…"], "content": "We're open Sunday 9 to 1"}'

# → {"data": [{"conversation_id": "a93e…", "status": "sent", "message_id": "…"},
#             {"conversation_id": "c41d…", "status": "forbidden"}], "total": 2}
GET/stats?period=week

Stats

Your business stats for the period week (default), month or year.

Uploading files POST /media

Upload the file as multipart/form-data in the file field and you get a media_id to send it as a document. The type is detected from the file's actual content (not the extension or the Content-Type you send) and the server generates the name. Only media_ids uploaded by your own business are accepted.

TypeMIMEMax size
JPEG, PNG, GIF, WebPimage/jpeg · image/png · image/gif · image/webp10 MB
PDFapplication/pdf25 MB
MP3, M4Aaudio/mpeg · audio/mp416 MB
MP4, MOVvideo/mp4 · video/quicktime64 MB

HTML, SVG, executables and any other type are rejected with 415 unsupported_media_type.

curl · PDF invoice
# 1) Upload the file (multipart, field "file")
curl -X POST "$BASE/media" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY" \
  -F "[email protected]"

# 201 → {"data": {"media_id": "https://…/business-media/…/3b0e….pdf",
#                 "mime_type": "application/pdf", "size_bytes": 48213}}

# 2) Send it as a document using the media_id
curl -X POST "$BASE/messages" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+18095551234",
    "type": "document",
    "media_id": "https://…/business-media/…/3b0e….pdf",
    "filename": "Invoice 1042.pdf",
    "caption": "Your November invoice",
    "idempotency_key": "invoice-1042"
  }'

Webhooks

If you give your key a webhook_url, LhamsApp notifies you with a signed POST when something happens. You receive the webhook_secret (it starts with whsec_) only once, when you create or rotate the key; the server always generates it.

Events

  • message.status — a message you sent through the API was sent: id, status ("sent"), to (the same number you sent), customer_id, conversation_id and timestamp.
  • message.inbound — a customer messaged you in a business thread: from, customer_id, conversation_id, message_id, content_type, timestamp and text. The customer is identified by customer_id ("cus_…"), a per-business pseudonymous identifier: always the same for that customer in your business, but different in every business, and it can't be used to recover their number. from carries the same value for compatibility. To reply, use POST /messages with conversation_id. text is null when the message is end-to-end encrypted.
Request you receive
POST /webhooks/lhamsapp HTTP/1.1
Content-Type: application/json
User-Agent: LhamsApp-Webhooks/1.0
X-LhamsApp-Timestamp: 1762092309
X-LhamsApp-Signature: sha256=5d41402abc4b2a76b9719d911017c592…

{"event":"message.status","data":{"id":"6f1c…","status":"sent","to":"+18095551234","customer_id":"cus_Q2x…","conversation_id":"a93e…","timestamp":"2026-11-02T14:05:09Z"},"timestamp":"1762092309"}
message.inbound
{
  "event": "message.inbound",
  "data": {
    "from": "cus_Q2x…",
    "customer_id": "cus_Q2x…",
    "conversation_id": "a93e…",
    "message_id": "…",
    "text": null,
    "content_type": "text",
    "timestamp": "2026-11-02T14:07:41Z"
  },
  "timestamp": "1762092461"
}

How to verify the signature

  1. Read the headers X-LhamsApp-Timestamp (Unix seconds) and X-LhamsApp-Signature (sha256=<hex>).
  2. Reject if the timestamp is more than 5 minutes off from your clock (prevents replays).
  3. Compute HMAC-SHA256(webhook_secret, timestamp + "." + raw_body) in lowercase hex, using the full secret, whsec_ prefix included.
  4. Compare with the signature in constant time. If it doesn't match, answer 401 and discard it.
Node.js
// Node.js 18+ · Express
import crypto from "node:crypto";
import express from "express";

const SECRET = process.env.LHAMSAPP_WEBHOOK_SECRET; // "whsec_…" in full, as is
const TOLERANCE_S = 300; // 5 minutes

const app = express();

// Important: the RAW body (Buffer). If you parse it and serialize it
// again, the signature won't match.
app.post("/webhooks/lhamsapp", express.raw({ type: "application/json" }), (req, res) => {
  const ts = req.get("X-LhamsApp-Timestamp") ?? "";
  const sig = req.get("X-LhamsApp-Signature") ?? "";

  if (!/^\d+$/.test(ts) || Math.abs(Date.now() / 1000 - Number(ts)) > TOLERANCE_S) {
    return res.sendStatus(400); // stale or missing timestamp: possible replay
  }

  const expected =
    "sha256=" +
    crypto.createHmac("sha256", SECRET).update(`${ts}.`).update(req.body).digest("hex");

  const a = Buffer.from(sig);
  const b = Buffer.from(expected);
  if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
    return res.sendStatus(401);
  }

  const { event, data } = JSON.parse(req.body.toString("utf8"));
  // Process it in the background and answer fast (2xx).
  queue.add(event, data);
  res.sendStatus(204);
});
Python
# Python 3.9+ · Flask
import hashlib
import hmac
import os
import time

from flask import Flask, abort, request

SECRET = os.environ["LHAMSAPP_WEBHOOK_SECRET"].encode()  # "whsec_…" in full
TOLERANCE_S = 300  # 5 minutes

app = Flask(__name__)


@app.post("/webhooks/lhamsapp")
def lhamsapp_webhook():
    ts = request.headers.get("X-LhamsApp-Timestamp", "")
    sig = request.headers.get("X-LhamsApp-Signature", "")
    body = request.get_data()  # exact body bytes

    if not ts.isdigit() or abs(time.time() - int(ts)) > TOLERANCE_S:
        abort(400)  # possible replay

    expected = "sha256=" + hmac.new(
        SECRET, ts.encode() + b"." + body, hashlib.sha256
    ).hexdigest()

    if not hmac.compare_digest(sig, expected):
        abort(401)

    payload = request.get_json()
    # Queue payload["event"] / payload["data"] and answer fast.
    return "", 204

Delivery and retries

  • Answer with a 2xx in under 5 seconds (the connection has a 3 s limit). Process in the background.
  • A 4xx, 5xx or timeout is retried with increasing backoff, up to 8 attempts. You may get the same event more than once: drop duplicates by message_id or id.
  • Redirects (3xx) aren't followed and your response body isn't read.

webhook_url rules

  • Only https://, with a domain name, no user:password in the URL and no fragment (#).
  • The domain must resolve only to public IPs. localhost, internal names (.local, .internal, .lan, .corp…), private, loopback, link-local (including the 169.254.169.254 cloud metadata), CGNAT and reserved IPs are rejected, on IPv4 and IPv6.
  • It's checked when saved and again on every delivery attempt. If it stops being safe, delivery is cancelled; a webhook is never sent unsigned.

Rotate your key POST /keys/rotate

Issues a new key with the same configuration (name, permissions, webhook_url, sandbox) and a new webhook_secret. The key you called with stops working right away, so store the new one before doing anything else. Returns 201; the key and secret are shown only once.

curl
curl -X POST "$BASE/keys/rotate" \
  -H "Authorization: Bearer $LHAMSAPP_API_KEY"
Response 201
{
  "data": {
    "id": "…", "name": "Online store", "permissions": ["messages", "contacts"],
    "is_active": true, "is_sandbox": false,
    "webhook_url": "https://example.com/webhooks/lhamsapp",
    "calls_today": 0, "calls_this_month": 0, "last_used_at": null, "inserted_at": "…"
  },
  "raw_key": "lhamsapp_live_…",
  "webhook_secret": "whsec_…",
  "warning": "Store this key securely. It will not be shown again."
}

Rotate your key periodically and whenever you suspect it leaked. You can also revoke it from the app.

Error codes

Errors come as {"error": "…", "code": "…"}. Code against the code (stable), not the error text.

HTTPcodeWhat it means
400—Required parameters are missing (for example, the multipart file field).
401invalid_api_keyThe key doesn't exist, was revoked or rotated, or you didn't send it.
403plan_inactiveYour plan is cancelled, expired or suspended, or doesn't include the API. The key works again once it's reactivated.
403—The key lacks the required permission: "API key lacks 'messages' permission" (or 'contacts'), or broadcast without the Enterprise plan.
403conversation_forbiddenThat conversation_id isn't one of your business threads with a customer who allows you to message them.
404no_recipientThat to can't be reached. Same answer whether they don't use LhamsApp, have no relationship with you, blocked you or their privacy doesn't allow it.
404contact_not_foundContact doesn't exist or has no relationship with your business (identical answer either way).
413file_too_largeThe file exceeds the limit for its type.
415unsupported_media_typeFile type not allowed (images, PDF, MP3/M4A and MP4/MOV only).
422invalid_requestInvalid data, for example an empty text.
422invalid_mediaThe media_id didn't come from this business's POST /media.
422empty_file · upload_failedEmpty file, or it couldn't be stored (retry).
422too_many_recipientsMore than 500 conversation_ids in one broadcast.
429quota_exceededYour daily or monthly quota is used up.
429rate_limitedToo many requests in a row. Wait retry_after seconds (also in the Retry-After header).

Privacy

  • No phone numbers exposed: no API response or webhook returns a customer's phone number; in message.inbound the customer arrives as customer_id, a per-business pseudonym that can't be linked across businesses. The only number you see is the one you sent yourself (the to in message.status).
  • No sweeping: responses are identical whether the number doesn't exist, has no relationship with you, blocked you or doesn't accept your messages. It can't be used to find out who uses LhamsApp.
  • Blocks and privacy are respected: if a customer blocks you or changes who can message them, the API stops reaching them.
  • End-to-end encryption: for encrypted inbound messages, the webhook doesn't include the text.
  • Only yours: each key only sees its own business's threads and files, never personal chats.

Questions about your integration? Email [email protected]. Found a vulnerability? Report it to [email protected].