Project Launcher

API & n8n

API Key

Add this as an x-api-key header in every request from n8n.

—
Endpoints
GEThttps://lunch.rahaty.shop/api/n8n/accounts

List active accounts — copy the id to use as account_id below

GEThttps://lunch.rahaty.shop/api/n8n/templates?account_id=…

List approved templates for an account

POSThttps://lunch.rahaty.shop/api/n8n/send

Send a text or template message — see examples below

Request Body Examples — POST /api/n8n/send

Each object in components maps to a section of your template. Parameters fill variables in order: {{1}} {{2}} etc. Only include sections your template actually uses.

{
  "phone":         "971501234567",
  "account_id":    "YOUR_ACCOUNT_ID",
  "type":          "template",
  "template_name": "order_confirmation",
  "language":      "ar",
  "components": [

    // Header — fills {{1}} in the header text
    {
      "type": "header",
      "parameters": [
        { "type": "text", "text": "Mohamed" }
      ]
    },

    // Body — fills {{1}}, {{2}}, {{3}} in order
    {
      "type": "body",
      "parameters": [
        { "type": "text", "text": "ORD-12345" },
        { "type": "text", "text": "149 درهم" },
        { "type": "text", "text": "2-3 أيام" }
      ]
    },

    // URL button — fills the dynamic URL suffix
    {
      "type":     "button",
      "sub_type": "url",
      "index":    "0",
      "parameters": [
        { "type": "text", "text": "track-ORD-12345" }
      ]
    },

    // Quick-reply button — payload sent back when tapped
    {
      "type":     "button",
      "sub_type": "quick_reply",
      "index":    "1",
      "parameters": [
        { "type": "payload", "payload": "CONFIRM_ORDER" }
      ]
    }

  ]
}

In n8n — replace hardcoded values with expressions:

{{ $json.customer_name }} → customer name from trigger

{{ $json.order_id }} → order ID from trigger

{{ $json.phone }} → customer phone number

Receive Events in n8n — Inbound Webhook

Every inbound message — including button taps and list selections — is forwarded to your n8n instance automatically. Set the env var below in Vercel, then create a Webhook trigger node in n8n to receive events.

Add to Vercel → Project → Environment Variables:

N8N_WEBHOOK_URLhttps://your-n8n.com/webhook/YOUR_ID

Events sent to n8n:

message— Any regular inbound text message
button_reply— Customer tapped a quick-reply button in a template
list_reply— Customer selected an item from a list template

Payload shape (button_reply example):

{
  "event":           "button_reply",
  "payload":         "CONFIRM_ORDER",
  "button_title":    "Confirm",
  "phone":           "971501234567",
  "contact_name":    "Mohamed",
  "contact_id":      "uuid",
  "conversation_id": "uuid",
  "account_id":      "uuid",
  "message_type":    "interactive",
  "body":            "[Button: Confirm]",
  "timestamp":       "2026-06-19T12:00:00.000Z"
}

n8n workflow tip

Add a Switch node after the Webhook trigger — branch on {{ $json.event }} to run different flows for button_reply vs message.

Use {{ $json.payload }} to match the button ID (e.g. CONFIRM_ORDER) and {{ $json.phone }} to send the follow-up template back via POST /api/n8n/send.