Creating customers through the API (AI file)
Download new-customer-api.llm.md
# OB_API: new_customer.create
version: 0.3-draft (2026-10-11). product: OrangeBoard (OB) PSA, https://ob.standardcomputer.com
goal: create a customer or a pre-customer, plus a site or contact, without crossing the convert boundary.
actor: an integration using an API key. Convert to client and quote accept stay with a human in the UI.
## AUTH
- Base URL: https://ob.standardcomputer.com/api/v1
- Header: Authorization: Bearer, plus the key. Content-Type: application/json.
- The key string starts with the prefix obk_. An admin creates it at Settings → Integrations → API keys. It is shown once and stored hashed. Never print, invent, or store a real key in docs, prompts, or logs. Read the key from the environment.
- Write implies read within the same area.
## SCOPES
tickets:read, tickets:write
clients:read, clients:write
contacts ride on clients. There is no contacts scope.
sites:read, sites:write
devices:read, devices:write
users:read
read-only. No users:write.
mentions:read, mentions:write
webhooks:read, webhooks:write
reports:read
read-only.
projects:read, projects:write
crm_leads:read, crm_leads:write
UI label "CRM: Leads (intake)".
crm_prospects:read, crm_prospects:write
kb:read, kb:write
kb_secrets:read
read-only by design.
No quotes scope. Quotes have no API-key surface.
## ERRORS
Every error body is {"error":"..."}.
- 400 malformed JSON or schema violation. Message form: "Invalid request: field: message". JSON null for a phone is 400.
- 401 missing, invalid, revoked, or expired key.
- 403 missing scope. The message names the scope.
- 422 business-rule refusal.
- 429 rate-limited CRM key, with Retry-After.
- 503 API kill switch off, or on CRM routes the CRM module, intake queue, or researcher API is off.
Traps: unknown client_id on POST /sites or POST /contacts → 422 {"error":"Unknown client."} (not 404). Site or contact under a pre-customer without crm_prospects:write → 422 (not 403).
## PHONE
Omit the field or send "" for no number. JSON null is 400.
On sites and contacts a non-empty phone is shape-checked: 10 digits, or 11 starting with 1; a trailing extension is allowed and stripped before the count; a leading + allows 8–15 digits; a single repeated digit is refused. Stored verbatim.
## POST /api/v1/clients
Scope: clients:write. Customer-side organizations only. No /api/v1/customers. isCustomer is computed. Sending relationship "lead" or another pre-customer stage is 422 — use POST /api/v1/crm/leads.
Required: name.
Optional: phone, website, relationship, industry, notes, address_line_1, address_line_2, city, county, postcode, country, main_site_name.
Address uses county. Sites use state. Unknown keys are dropped with no error, so state on this route vanishes and county stays empty.
201: client object (legacy PSA field names) + main_site_id. qbo_provisioning is always present (ok / created / qbo_customer_id, or ok:false + a warning). The client is created even when QuickBooks fails.
GET /api/v1/clients, GET /api/v1/contacts, and GET /api/v1/sites return customer-side rows. ?include_pre_customer=true widens the list and requires crm_prospects:read; without that scope the parameter is 403.
Example body (fictional): {"name":"Example Dental","city":"Example City","county":"Example County","country":"US","main_site_name":"Main office"}
## POST /api/v1/crm/leads
Scope: crm_leads:write. Pre-customers. Lands in the intake queue.
Required: practice_name (alias name).
Optional: contact_name, contact_email, contact_phone, website, address_line_1, address_line_2, city, state, postcode, org_npi, notes, source, source_detail, research_notes, confidence (0–1), external_id, idempotency_key.
No country field. contact_email is not email-validated here. contact_phone is not shape-checked here. Validation runs at promote.
201. Idempotency replay: 200 with created:false. Response may omit address and notes.
dedupe_state: clean | customer_match | precustomer_match | fuzzy.
status: pending | promoting | approved | merged | rejected.
A trusted key whose confidence clears the auto-approve threshold, with dedupe_state clean, can return auto_approved:true and client_id.
503 when the CRM module, intake queue, or researcher API is off.
CSV import uses camelCase (practiceName). This route uses snake_case (practice_name).
Example body (fictional): {"practice_name":"Example Dental","contact_name":"Example Contact","contact_email":"front-desk@example.com","city":"Example City","state":"EX","source":"website"}
## POST /api/v1/sites
Scope: sites:write.
Required: client_id, name.
Optional: phone, address_line_1, address_line_2, city, state, postcode, country.
Phone: "" ok, null 400, otherwise shape-checked.
201 does not echo address fields. GET /api/v1/sites/{id} reads them back.
Unknown client_id → 422 {"error":"Unknown client."}. Pre-customer parent without crm_prospects:write → 422.
## POST /api/v1/contacts
Scope: clients:write.
Required: client_id, name.
Optional: site_id, email (RFC-validated), phone, mobile (shape-checked), job_title, role, is_primary.
201 uses legacy names (emailaddress, phonenumber, and similar). site_id is accepted and not echoed.
422 Unknown client. 422 site not under the client. 422 pre-customer parent without crm_prospects:write.
## UI_ONLY
- Convert to client: deliberate UI gate. sales-all or admin. Fully audited. Optional QBO, contract, and onboarding-ticket steps. No REST. PATCH /api/v1/clients/{id} that would cross pre-customer → customer returns 422: "This stage change would make a pre-customer org a client. Use Convert to client (CRM)…".
- Quote accept does not convert. Public /quote/{token} and staff Record outcome share one handler and write the quote only: status SENT→ACCEPTED, acceptedAt, frozen acceptedSnapshot, journal events. relationship, isCustomer, linked deal, and pipeline stage stay unchanged. A lead that accepts stays a lead. Ticket or project handoff is a separate staff-confirmed action. No quotes API.
- Log touch is manual. No confirmed REST endpoint. Helpdesk email intake may log an inbound email from a known contact; that is not an outreach-thread match.
- CRM module off: /crm pages and CRM API disabled (redirect /console, including admins). POST /api/v1/crm/leads returns 503. "+ Client" / "+ Add client" remain for ADMIN and still create customer-side rows. The Lead/MQL/Prospect choices on that form currently also save customer-side rows (isCustomer true) and skip Convert — do not use them for a pre-customer until that fix ships. Ticket overflow "Convert to CRM lead…" can remain visible and fails at submit: "The CRM module is turned off (Admin → CRM)."
## RULES
- Confirm with a human before creating or converting records.
- Never output client names, contacts, PHI, or key material. Examples stay fictional (Example Dental).
- Give the key only the scopes this task needs.