developers.md

Hamla for developers

Hamla is an AI marketing agent a business installs with one script tag. Events are free and unmetered on every plan; contacts and sending are what cost.

Install

Add before </head>. The business id comes from Settings → Website in Hamla and is public — it appears in every page that loads the SDK.

<script src="https://app.hamla.io/s/{businessId}.js" async></script>

This covers visits, sources, on-site behaviour, and hamla.track() calls made in the page. No key: a published bundle cannot hold one.

No account yet — POST /api/install

If you are an agent building someone a site, you do not have their Hamla login and you will not get one mid-task. This returns a working install immediately, with no authentication and no key issued.

curl -X POST https://app.hamla.io/api/install \
  -H "Content-Type: application/json" \
  -d '{
    "website": "raqmi.co",
    "name": "Raqmi",
    "locale": "en"
  }'
{
  "success": true,
  "data": {
    "businessId": "cmf8q1x4k0000",
    "snippet": "<script src=\"https://app.hamla.io/s/cmf8q1x4k0000.js\" async></script>",
    "claimUrl": "https://app.hamla.io/claim/9f3c...",
    "expiresAt": "2026-09-19T08:00:00.000Z",
    "note": "This install records anonymous traffic only until it is claimed. Print the claim link for the person who owns the site — it is single-use and expires."
  },
  "message": "Install created"
}

Put snippet in the page. Print claimUrl for the person who owns the site — that is the one step only you can take, and the install is deleted if nobody follows it.

What an unclaimed install may do, and what it refuses:

The owner opening that link sees their own traffic — visitors, sources, how many reached checkout and left — and one button. Not a signup form.

Lovable, v0, Bolt

They cannot install a skill or connect an MCP server, so paste this in:

Add Hamla to this site so I get analytics and marketing on it.

1. POST to https://app.hamla.io/api/install with JSON {"website": "<this site's domain>"}.
   No API key, no account, no auth header. It returns
   { "data": { "businessId", "snippet", "claimUrl" } }.
2. Put the returned "snippet" string in the <head> of every page, exactly as given.
   Do not invent or edit the business id inside it.
3. When you are done, show me the "claimUrl" value. I need it to take ownership —
   it works once and expires in 72 hours.

Rules: never send a customer's email or phone to Hamla from this site, and never
put a Hamla secret key in front-end code. Neither is needed for the above.

Who someone is — POST /api/sdk/identify

Call it from your server when someone signs up, and again at login, before the first event about them. Same secret key as track.

curl -X POST https://app.hamla.io/api/sdk/identify \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "identity": { "email": "omar@raqmi.co", "platformCustomerId": "user_812" },
    "profile": { "name": "Omar Al Saleh" },
    "method": "signup"
  }'

It creates or enriches the contact, links their anonymous visits when you pass the visitorId cookie, and records that the business put this person in Hamla, which is what lets campaigns email them. track never records that: a contact Hamla only learned about from an event cannot be messaged, so a welcome sequence on account_created reaches nobody unless identify ran first. When that happens, the track response says so in warnings: "campaigns will not reach this contact". Permission is recorded once and never re-granted after an unsubscribe. SMS and WhatsApp also need the person's own opt-in for that channel.

Node: await hamla.identifyNow({ identity, profile, method }), or hamla.identify(...) to fire and forget. In the page: hamla.identify({ email }).

Events — POST /api/sdk/track

Server-side. Requires a secret key from Settings → API keys.

Authorization: Bearer sk_live_...

A publishable key (pk_live_) is refused with 403 here: it ships in page source, so honouring it would let any visitor invent revenue.

curl -X POST https://app.hamla.io/api/sdk/track \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "event": "subscription_started",
    "type": "purchase",
    "identity": { "email": "omar@raqmi.co" },
    "value": 29,
    "currency": "JOD",
    "idempotencyKey": "invoice_9911"
  }'

Fields

What type means

Your event name stays yours, in your own language. type says what Hamla should do with it.

Backfill — POST /api/sdk/track/batch

1–500 past events per request, same field rules, each with its real occurredAt. Backfilled history never starts a campaign and never fires a segment-entry trigger. Give every row an idempotencyKey and the job is safe to re-run.

Browser

hamla.track('download_ebook', { asset: 'guide.pdf' }) — no key needed. These count as deliberate and can start campaigns. Anything involving money or your own records should come from your server.

Node

npm install @gethamla/node

Wraps the same HTTP API with queueing and retries. Never throws, never blocks; call flush() before a serverless runtime freezes.

MCP

https://app.hamla.io/mcp

OAuth. Registry name io.hamla/hamla. Exposes the same tools Hamla's own agent runs on — analytics, campaigns, contacts, segments, imports.