Quickstart
Get a test key, ask for the offers on an order, show them, record the yes and verify the signed webhook.
Sign in to see samples with your own test keys.
What you will build
Five calls take an order from your app to a recorded yes. Your server signs the order. Your app asks Munja for the offers, shows them, and tells Munja when the customer says yes. Munja then sends a signed webhook to your server.
- Get your test keys.
- Ask for the offers (
POST /v1/offers). - Render them.
- Record the yes (
POST /v1/offers/{impression}/accept). - Verify the
offer.acceptedwebhook.
Everything here uses test mode. No one is charged or paid, and test data stays apart from live data. This page uses real endpoints only. The API reference lists all of them and /openapi.json is the machine-readable spec.
1. Get your test keys
Create a free host account at /signup. Then open your dashboard:
- Publishable key
pk_test_...and signing secretmss_test_...: Install. The publishable key is safe in a browser. Signing secrets and secret keys are server only. - Secret key
sk_test_...: Settings, API keys. It is shown once.
Sign in to see the samples with your own test publishable key. Secret keys are never filled in for you.
Live keys (pk_live_, sk_live_) exist but stay off while you build. Do not use them here.
const res = await fetch("https://getmunja.com/v1/events", {
headers: { Authorization: `Bearer ${process.env.MUNJA_SECRET_KEY}` }, // sk_test_...
});
console.log(res.status, await res.json()); // 200 { object: "list", data: [...], has_more: false }2. Sign the order (recommended)
A signature proves the order came from your server, so fake traffic cannot earn from your account. It is the hex HMAC-SHA256 of order_id + "." + email, with the email trimmed and lowercased, using your signing secret.
A wrong signature is always rejected (invalid_signature). A missing one is accepted unless you turn on require signed orders in your settings (signature_required). While you are trying things out you can skip this step.
import { createHmac } from "node:crypto";
export function signOrder(orderId, email) {
return createHmac("sha256", process.env.MUNJA_SIGNING_SECRET) // mss_test_...
.update(`${orderId}.${email.trim().toLowerCase()}`)
.digest("hex");
}3. Ask for the offers
POST /v1/offers takes your publishable key and one order, and returns the offers to show with an impression token on each. Call it after payment, when the confirmation page, email or screen is built. surface is thank_you, exit, email or portal.
context carries what you know about the order, such as zip, newCustomer or orderTotal. It decides which offers are relevant. See Order context for the fields by industry.
An empty data list means show nothing. empty_reason says why, for example no eligible offers. It is for your developer, never for the customer. Asking again for the same order returns the same offers with replayed: true.
Errors come back as { error: { type, code, message, param } }. A browser can call this endpoint directly because it needs only the publishable key.
const res = await fetch("https://getmunja.com/v1/offers", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
key: "pk_test_...",
order: { id: "ORDER-1042" /* , signature: signOrder("ORDER-1042", "dana@example.com") */ },
surface: "thank_you",
customer: { email: "dana@example.com", name: "Dana" },
context: { zip: "60614", newCustomer: true, orderTotal: 129.0 },
}),
});
const { data: offers, empty_reason } = await res.json();
if (!offers.length) console.log("Nothing to show:", empty_reason);{
"object": "offer_list",
"decision": "dec_...",
"livemode": false,
"data": [
{
"impression": "imp_...",
"position": 1,
"partner": "Example Partner",
"category": "Cleaning",
"headline": "...",
"body": "...",
"price": "...",
"cta": "...",
"consent": "Shares your name & email with Example Partner. Nothing shared if you skip.",
"consent_version": "2026-11-30.3",
"yes_tier": "contact"
}
],
"moment": { "layout": "stack", "title": "...", "fine": "..." }
}4. Render the offers
Show each offer's headline, body and price, one button with cta, and the consent sentence next to it, exactly as returned. The consent text is versioned and saved with every yes, so do not rewrite it.
Offers with yes_tier of call or quote also carry call_consent. Show it next to an unchecked box and collect the extra fields. Accept an offer has the details.
When the customer says no, call POST /v1/offers/{impression}/dismiss. Offers should look like part of your page and be labeled as picked by you. Not sure how it should look? Try them in the sandbox.
<!-- Show offer.headline, offer.body, offer.price, one button with offer.cta,
and offer.consent next to it. Do not edit the consent text. -->
<article class="offer">
<h3>{{ offer.headline }}</h3>
<p>{{ offer.body }}</p>
<button data-impression="{{ offer.impression }}">{{ offer.cta }}</button>
<small>{{ offer.consent }}</small>
<button data-dismiss="{{ offer.impression }}">No thanks</button>
</article>5. Record the yes
When the customer presses the button, send the impression token with their email and name. Munja creates the lead and the consent record and charges the partner. Retrying the same token is safe and returns the same lead.
If the response has continueUrl, show a "Continue to the partner" button that opens it in a new tab after your confirmation message. Never redirect the customer on your own.
const res = await fetch(`https://getmunja.com/v1/offers/${encodeURIComponent(offer.impression)}/accept`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: "dana@example.com", name: "Dana" }),
});
const yes = await res.json(); // { object: "acceptance", lead: "lead_...", status: "accepted", message: "...", livemode: false }
if (yes.continueUrl) window.open(yes.continueUrl, "_blank"); // optional "Continue to partner" button6. Handle the webhook
Hosts receive offer.accepted for every yes. It carries ids and amounts, never the customer's name, email, phone or ZIP. Create an endpoint with your test secret key. Its URL must be https, so use a tunnel while developing on your own machine. If you omit events, a host endpoint listens for offer.accepted and a partner endpoint listens for lead.created.
Each delivery has an X-Munja-Signature header: t=<unix seconds>,v1=<hex>, where the hex is the HMAC-SHA256 of t + "." + raw body with the endpoint secret. Check it against the raw body before parsing, reject timestamps more than 5 minutes old, and compare in constant time.
Answer with any 2xx within 10 seconds, and de-duplicate on event.id. Failed deliveries retry after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours. Use Send test event on the endpoint in your dashboard to send a webhook.test without making a yes. More in webhook signatures.
const res = await fetch("https://getmunja.com/v1/webhook_endpoints", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.MUNJA_SECRET_KEY}`, "Idempotency-Key": "create-endpoint-1", "Content-Type": "application/json" },
body: JSON.stringify({ url: "https://example.com/munja/webhooks", events: ["offer.accepted"] }),
});
const { id, secret } = await res.json(); // keep secret (whsec_...) in your secrets managerimport { createHmac, timingSafeEqual } from "node:crypto";
/** rawBody must be the exact request body string, before any JSON parsing. */
export function verifyMunja(rawBody, header, secret, toleranceSeconds = 300) {
const parts = Object.fromEntries((header ?? "").split(",").map((p) => p.split("=", 2)));
const t = Number(parts.t);
if (!Number.isFinite(t) || !parts.v1) return false;
if (Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
const expected = Buffer.from(createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex"));
const given = Buffer.from(parts.v1);
return expected.length === given.length && timingSafeEqual(expected, given);
}
// In your handler: verifyMunja(rawBody, req.headers["x-munja-signature"], process.env.MUNJA_WEBHOOK_SECRET)
// then de-duplicate on event.id and return 200.{
"id": "evt_...",
"object": "event",
"type": "offer.accepted",
"livemode": false,
"created": 1767225600,
"data": {
"object": {
"object": "offer_acceptance",
"id": "lead_...",
"offer": "ofr_...",
"partner": "acct_...",
"price_cents": 3000,
"merchant_share_cents": 2100,
"surface": "thank_you",
"yes_tier": "contact",
"source": "human",
"status": "charged",
"created": 1767225600
}
}
}Try it with fake orders
The sandbox page has three fictional orders (a move, a salon booking and an online order). Pick one, paste your test publishable key, and see what comes back and how it renders. Accepting an offer there creates a test lead, so you can watch the offer.accepted webhook arrive at your endpoint.
If the list is empty, your test account has no approved partner offers for that order yet. The response says why in empty_reason. Partners and their offers are approved from your dashboard.
Limits and good habits
- JSON in and out, snake_case keys, money as integer cents, times as Unix seconds.
- Browser endpoints are limited per IP address. Over the limit you get
429withrate_limited, so wait and retry. - Send an
Idempotency-Keyheader on server POST calls. Keys are kept for 24 hours. - Every secret-key response carries a
Request-Idheader. Include it when you contact support@getmunja.com. - Ignore response fields you do not know. New ones can appear.
Using an AI coding tool or agent? Point it at /llms.txt or /llms-full.txt.