CRM
CRM endpoints need the CRM product, plus crm:record:read to read and crm:record:write to change anything. Creating or renaming companies also needs crm:company:create or crm:company:update. Full details: CRM API.
Recipe: turn a website form into a lead and a deal
curl -s -X POST "$OPEX/api/crm/contacts" \ -H "X-API-Key: $OPEX_API_KEY" -H "content-type: application/json" \ -d '{"email":"[email protected]","name":"Rudi Hartono","company":"Tirta Mas","source":"website form"}' \ | jq '{id, email, name, status, source}'{ "id": "a0279c49-9498-4684-a5eb-4daff77c39e1", "name": "Rudi Hartono", "status": "lead", "source": "website form"}Contacts are unique by email. When the same person fills in the form again, the call answers 200 with the existing contact and only fills its blank fields, so the sync can run as often as you like.
CONTACT_ID=a0279c49-9498-4684-a5eb-4daff77c39e1
curl -s -X POST "$OPEX/api/crm/deals" \ -H "X-API-Key: $OPEX_API_KEY" -H "content-type: application/json" \ -d "{\"name\":\"Tirta Mas water plant maintenance\",\"contactId\":\"$CONTACT_ID\", \"amountCents\":12000000000,\"currency\":\"IDR\"}" \ | jq '{id, name, stage, amount_cents, currency}'{ "id": "ac455537-d864-448a-a7be-71f3f8313ef4", "name": "Tirta Mas water plant maintenance", "stage": "lead", "amount_cents": 12000000000, "currency": "IDR"}amountCents is in minor units: 12000000000 is Rp 120.000.000.
Recipe: log a meeting and move the deal
DEAL_ID=ac455537-d864-448a-a7be-71f3f8313ef4
curl -s -X POST "$OPEX/api/crm/activities" \ -H "X-API-Key: $OPEX_API_KEY" -H "content-type: application/json" \ -d "{\"subjectType\":\"deal\",\"subjectId\":\"$DEAL_ID\",\"kind\":\"meeting\", \"title\":\"Site visit\",\"body\":\"Walked the pump house with the plant manager.\"}" \ | jq '{id, kind, title, occurred_at}'
curl -s -X POST "$OPEX/api/crm/deals/$DEAL_ID/move" \ -H "X-API-Key: $OPEX_API_KEY" -H "content-type: application/json" \ -d '{"stage":"qualified"}' | jq '{id, stage, closed_at}'{ "id": "5d66a85c-833b-478c-bdbc-50caea354d01", "kind": "meeting", "title": "Site visit", "occurred_at": 1794051343536 }{ "id": "ac455537-d864-448a-a7be-71f3f8313ef4", "stage": "qualified", "closed_at": null }The move is recorded on the deal’s timeline. Moving to lost needs a lostReason; moving to won or lost sets closed_at.