# External order intake — `external-order-intake`

## Public doc (single page)

Human-readable spec (English UI, copy buttons): [`docs/mojeeb/index.html`](../mojeeb/index.html) — served at `https://docs.dnadi.food/`.

## Endpoint

```http
POST https://n8n.dnadi.food/webhook/external-order-intake
```

## Auth

- Header: `x-api-key` (or `X-Api-Key`)
- Compared to env on the n8n container: **`DNADI_WEBHOOK_X_API_KEY`**
- If env is non-empty and the header does not match → **401** `{ "ok": false, "error": "unauthorized" }`

## `order_type`

Accepted **either** English **or** Arabic (exact Arabic tokens as in the doc):

| Arabic | English (stored internally) |
|--------|----------------------------|
| جديد | new |
| تعديل | modify |
| استعجال | urgent |
| الغاء or إلغاء | cancel |
| دعم | support |

## Canonical JSON fields (required unless noted)

| Field | Required |
|-------|----------|
| `order_type` | yes |
| `source` | yes |
| `customer_name` | yes |
| `address` | yes |
| `phone` | yes |
| `requested_products` | yes (non-empty array) |
| `raw_customer_message` | yes |
| `customer_message_summary` | yes |
| `order_number` | no |
| `alternate_phone` | no |
| `customer_notes` | no |

## Optional Arabic / nested aliases (workflow)

The Code node in [`workflows/n8n-external-order-intake.json`](../../workflows/n8n-external-order-intake.json) also reads selected Arabic top-level keys (e.g. `نوع الطلب`, `مصدر`, `الاسم`, …) and nested `عميل` / `طلب` shapes when present.

## Routing

After validation, `route_key` is one of: `route_new`, `route_modify`, `route_urgent`, `route_cancel`, `route_support`.  
`route_new` forwards to `phone-order-parse`; other branches are stubs until you wire them in n8n.

## Re-import

Import [`workflows/n8n-external-order-intake.json`](../../workflows/n8n-external-order-intake.json), attach Postgres where needed later, set **HTTP Request** credential for `phone-order-parse`, set env **`DNADI_WEBHOOK_X_API_KEY`**, then **Activate**.
