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.
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 URL
https://api.lhamsapp.com/api/business/v1
Format
JSON (UTF-8). Files are uploaded as multipart/form-data.
Phone numbers
International E.164 format: +, country code and number (7 to 15 digits). Spaces, dashes, dots and parentheses are ignored.
Requirements
An 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>.
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
Limit
Value
When exceeded
Burst per key
120 requests per minute
429 rate_limited
Daily and monthly quota
Depends on your plan. Defaults: Business 200/day and 1,000/month; Enterprise 20,000/day with no monthly cap.
429 quota_exceeded
Contact lookups
100 per hour per key
429 rate_limited
Broadcast
Up to 500 threads per call (Enterprise plan)
422 too_many_recipients
Listings
limit 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.
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"
}'
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.
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.
Type
MIME
Max size
JPEG, PNG, GIF, WebP
image/jpeg · image/png · image/gif · image/webp
10 MB
PDF
application/pdf
25 MB
MP3, M4A
audio/mpeg · audio/mp4
16 MB
MP4, MOV
video/mp4 · video/quicktime
64 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.
Read the headers X-LhamsApp-Timestamp (Unix seconds) and X-LhamsApp-Signature (sha256=<hex>).
Reject if the timestamp is more than 5 minutes off from your clock (prevents replays).
Compute HMAC-SHA256(webhook_secret, timestamp + "." + raw_body) in lowercase hex, using the full secret, whsec_ prefix included.
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.
HTTP
code
What it means
400
—
Required parameters are missing (for example, the multipart file field).
401
invalid_api_key
The key doesn't exist, was revoked or rotated, or you didn't send it.
403
plan_inactive
Your 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.
403
conversation_forbidden
That conversation_id isn't one of your business threads with a customer who allows you to message them.
404
no_recipient
That 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.
404
contact_not_found
Contact doesn't exist or has no relationship with your business (identical answer either way).
413
file_too_large
The file exceeds the limit for its type.
415
unsupported_media_type
File type not allowed (images, PDF, MP3/M4A and MP4/MOV only).
422
invalid_request
Invalid data, for example an empty text.
422
invalid_media
The media_id didn't come from this business's POST /media.
422
empty_file · upload_failed
Empty file, or it couldn't be stored (retry).
422
too_many_recipients
More than 500 conversation_ids in one broadcast.
429
quota_exceeded
Your daily or monthly quota is used up.
429
rate_limited
Too 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.