Awaphele Docs Main site
Docs/Developers

API

Connect your website, app or portal to Business Suite with an API key.

There are separate APIs, each with its own kind of key. Admins make keys in the app under Settings, API keys. The full key is shown once. Only a hash is stored, so a lost key is replaced, not recovered.

Send the key as a header, Authorization: Bearer <key>. All responses are JSON. Examples use crm.example.co.za, which is your own copy's address.

KeyStarts withCan doCannot do
Websitebsw_Send in an enquiry, report a problem (ticket)Read anything
Appbsa_Add or update customers (contacts), report a problem (ticket)Read anything
Clientbsc_Read one company's issued quotes and invoices, and their support ticketsChange anything

Each kind works only on its own calls: a website key cannot add contacts, an app key cannot send enquiries, and a client key cannot write. Tickets are the one call both website and app keys can make. Revoke a key and it stops at once.

Keep keys private

Keep keys in your calling site's config file outside the web root, never in page source or a repository. Set CORS_ALLOWED_ORIGINS in your copy's .env only if a browser will call the API directly.

Website API

POST /api/v1/leads

FieldNotes
nameRequired, up to 150 characters
emailRequired
phone, company, sourceOptional
messageOptional, up to 2000 characters
websiteA hidden field real visitors leave empty (see below)

An enquiry creates a contact (matched on email, so repeat visitors are not duplicated), a lead in the pipeline and a follow-up task due tomorrow. The same person writing again within a day adds to their open lead instead of making a new one.

Reply: 201 {"received": true}. Nothing else is ever sent back, so a leaked website key cannot read customer data.

Put a hidden website input in your form. Real visitors never fill it in, bots do. Those get a fake success and nothing is saved.

Limits: 10 a minute per visitor address and 200 an hour per key (429 when exceeded).

// On the company website (server side, so the key never reaches the browser)
$ch = curl_init('https://crm.example.co.za/api/v1/leads');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer bsw_...', 'Content-Type: application/json', 'Accept: application/json'],
    CURLOPT_POSTFIELDS => json_encode(['name' => $_POST['name'], 'email' => $_POST['email'], 'message' => $_POST['message'], 'source' => 'Contact page', 'website' => $_POST['website'] ?? '']),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($ch);

Calling it from a visitor's browser instead needs the site listed in CORS_ALLOWED_ORIGINS, and the key will be visible to anyone who views the page source. It can only send enquiries, but the server-side way is better.

App API

For a client's own app or database (for example one running on Ikhaya) that should keep its customers in Business Suite.

POST /api/v1/contacts creates a customer, or updates the one with the same email (case does not matter).

FieldNotes
name, emailRequired
phone, job_title, company, notesOptional

Updating only fills in or adds. An empty or missing field never wipes what is already held, a company is only attached if the contact has none, and a note is added once (sending the same note again does not repeat it).

Reply: 201 {"id": 12, "created": true} for a new customer, 200 {"id": 12, "created": false} for an existing one. Limit: 120 a minute per key.

// From the app's server, whenever someone signs up or changes their details
await fetch('https://crm.example.co.za/api/v1/contacts', {
  method: 'POST',
  headers: { Authorization: 'Bearer bsa_...', 'Content-Type': 'application/json', Accept: 'application/json' },
  body: JSON.stringify({ name: user.name, email: user.email, phone: user.phone, company: user.company }),
});

Tickets (support)

For a website's "report a problem" form, an app's error reports, or a monitor that raises an alert. Website and app keys can use it.

POST /api/v1/tickets

FieldNotes
subject, messageRequired (subject up to 200 characters, message up to 5000)
name, email, phoneOptional. With an email that matches a contact, the ticket joins that customer and their company
priorityOptional: low, normal (the default), high or urgent. Sets the reply and fix deadlines
external_refOptional: your own id for the problem, for example uptime:shop-site
statusOptional: open (the default) or resolved

Reply: 201 {"received": true, "action": "created", "data": {"number": "TCK-0007", "status": "open", "status_url": "..."}}. The status_url is the customer's own page for the ticket. Anyone holding that long link can read it and reply.

Repeat alerts

With an external_ref, a report that matches a ticket still open from the same key is added to that ticket (200, "action": "updated") instead of making a new one. Sending "status": "resolved" with the same ref closes it, so a monitor can open a ticket when a site goes down and close it when it recovers.

  • A ticket that is already resolved is never reopened. The problem coming back is a new ticket.
  • Resolving something that is not open does nothing ("action": "ignored").
  • References are per key, so two systems can use the same wording without clashing.
  • A report with no name or email is treated as a system alert and shown as an update line, not as something the customer said.
  • Business Suite does not email the person who submitted a ticket. That would let anyone make it send mail to any address. Your staff reply from the ticket.

A hidden form field called website that visitors never fill in works as a bot trap, as in the enquiry call. Limit: 20 a minute per address and 600 an hour per key.

// An uptime monitor, every minute
const down = !(await fetch('https://shop.example.co.za')).ok;
await fetch('https://crm.example.co.za/api/v1/tickets', {
  method: 'POST',
  headers: { Authorization: 'Bearer bsa_...', 'Content-Type': 'application/json', Accept: 'application/json' },
  body: JSON.stringify({
    subject: 'Shop site is down', message: down ? 'No response' : 'Back up',
    external_ref: 'uptime:shop', priority: 'urgent', status: down ? 'open' : 'resolved',
  }),
});

Client API

A client key can be tied to one company, and then sees only that company whatever else is asked. Or it can be left untied for a portal that looks clients up itself, and then adds ?company_id= to every call. Drafts are never shown.

CallReturns
GET /api/v1/client/summaryOpen invoices, amount outstanding, overdue invoices and amount
GET /api/v1/client/documentsA page of issued documents, newest first. Filters: type=invoice|quote, status=sent|paid|accepted|declined|cancelled, page
GET /api/v1/client/documents/{number}One document with its lines and payments, for example INV-0001
GET /api/v1/client/ticketsA page of the company's support tickets, newest first. Filters: status=open|pending|resolved, page
GET /api/v1/client/tickets/{number}One ticket with its conversation, for example TCK-0007

Each document has number, type, status, is_overdue, issue_date, due_date, subtotal, vat_rate, vat_amount, total, amount_paid, balance and view_url. Amounts are Rand as text with two decimals. The view_url is the customer's own printable copy. Anyone holding that long link can open it.

Tickets show number, subject, status, priority, created_at, resolved_at and status_url. A single ticket adds its messages, where from is customer or support. Internal notes and system lines are never included.

Limit: 120 a minute per key. A wrong or missing company gives 404, the same answer for "not yours" and "does not exist".

Setting it up

  1. Sign in as an admin and open API keys.
  2. Make a Website key for the company site, an App key for an app or database, and a Client key for each client (or one untied key for the portal).
  3. Put each key in the calling system's config file, outside the web root.
  4. Test with one call, then check the lead, contact or ticket appeared in Business Suite.