3.1 KiB
3.1 KiB
API + MCP Layer
Environment
Add to .env.local:
NEXT_PUBLIC_POCKETBASE_URL=http://127.0.0.1:8090
PB_ADMIN_EMAIL=your_admin_email
PB_ADMIN_PASSWORD=your_admin_password
AGENT_API_KEY=replace_with_secure_token
ORDER_ITEMS_COLLECTION=order_items
REST Endpoints
GET /api/v1/healthGET /api/v1/orders?page=1&perPage=50&status=newPOST /api/v1/orders/from-quoteGET /api/v1/collection-pool?page=1&perPage=50&status=queuedPATCH /api/v1/order-items/{id}/statusGET /api/v1/quotes/next-number— atomicQ-YYYY-MM-NNNcounter via thequote_counterscollection. Used by the quote form and the inbound email pipeline.
Auth for agent routes:
- Header:
Authorization: Bearer <AGENT_API_KEY>
POST /orders/from-quote body:
{ "quote_id": "QUOTE_RECORD_ID" }
PATCH /order-items/{id}/status body supports:
{
"item_status": "processed",
"drv_status": "assigned",
"notes": "Assigned to route 2"
}
MCP Endpoint
POST /api/mcp
Supported methods:
tools/listtools/call
Available tools:
orders.listorders.create_from_quotecollection_pool.listorder_items.update_statusquotes.create_from_email— create a new quote (with customer/company/items) from a parsed email payload. Idempotent onmessage_id. Attachments are no longer uploaded inline in this call — the legacyattachmentsfield in the payload is accepted but ignored. After the create call returns the new quote id, callattachments.upload_for_quoteonce per file. This split exists because embedding base64 attachments in the create POST would blow past the Next.js 1 MB request body limit on a 5 MB PDF.attachments.upload_for_quote— upload a single attachment (PDF, image, Word, Excel, CSV, plain text, or any binary up to 25 MB) to an existing quote. One call per file. Errors are surfaced per-attachment so a single bad file does not roll back the quote.quotes.append_reply— append a structured reply to an existing quote. Matches byIn-Reply-Toheader first, thenQ-YYYY-MM-NNNin the subject.quotes.find_by_message_id— look up a quote by the inbound email's RFC 5322Message-IDheader.
The quotes.* tools are the inbound side of the Quote Email Monitor n8n workflow. They are the only path new quotes and replies should be created through. The orders.* and order_items.* tools are likewise the only path for the orders side.
Notes
ORDER_ITEMS_COLLECTIONcontrols where order-item writes/updates go.- Set
ORDER_ITEMS_COLLECTION=order_itemsonce new collection is created/imported. - Status endpoint accepts
driver_statusinput and normalizes todrv_status. quotes.create_from_emailmust receive amessage_idfor idempotency — duplicate sends of the same email return the existing record withdeduped: true.quotes.append_replyreturnsmatched_by: 'in_reply_to' | 'subject' | 'none'. The'none'case is the workflow's signal to move the email toINBOX.Quotes-Unmatchedand not create a reply row.