Phonebook API¶
This document describes how an external system can create, update, retrieve, search and delete contacts in the Kewbot Phonebook through the API.
For sending template messages, see API Integration – Send Template.
General settings¶
- URL:
https://kewbot.com/api/phonebook.php - Authentication: Unique token per company, the same one used in
sendTemplate.php. Each token can only access the contacts of its own company. - Format:
application/json - Method:
POST - Responses: Structured JSON.
Request structure¶
All operations share the same URL and are distinguished by the action field:
curl -X POST https://kewbot.com/api/phonebook.php \
-H "Content-Type: application/json" \
-d '{
"token": "abcdefghilmnopqrstuvz1234567890",
"action": "upsert",
"phone": "5491112345678",
"name": "Juan Perez",
"customer_id": "CLI-27544",
"notes": "Home plan customer",
"tags": ["VIP"],
"attributes": {
"zone": "Almafuerte",
"plan": "fiber_500"
}
}'
Request fields¶
| Field | Type | Required | Description |
|---|---|---|---|
token |
string | Yes | API token assigned to the company. |
action |
string | Yes | Operation to perform: create, update, upsert, delete, get or list. |
phone |
string | Yes (except list) |
Contact phone in international format. It is the contact key: it is normalized to digits only (+54 9 11 1234-5678 is equivalent to 5491112345678). |
name |
string | Depends on action | Contact name. Required for create and, when the contact does not exist, for upsert. Optional for update, but it cannot be sent empty. |
customer_id |
string | No | Customer identifier in the external system. |
notes |
string | No | Contact notes. |
tags |
array of strings | No | Tags by name. They must already exist in Kewbot (see Contact tags); if any does not exist, the request is rejected. When sent, it replaces the contact's current tags. |
attributes |
object | No | Free-form contact attributes (key/value). When sent, it replaces the contact's current attributes. |
search |
string | list only |
Text to search in phone, name or customer_id. Minimum 3 characters. |
limit |
number | No | list only. Results per page (1 to 200, default 50). |
offset |
number | No | list only. Number of results to skip, for pagination. |
Available actions¶
action |
If the phone does not exist | If the phone already exists | Typical use |
|---|---|---|---|
create |
Creates the contact (201). |
409 error; nothing is modified. |
Strict creation, avoids overwriting an existing contact. |
update |
404 error; nothing is created. |
Modifies only the fields sent (200). |
Strict update, avoids creating contacts from a mistyped phone. |
upsert |
Creates the contact (201). |
Modifies the fields sent (200). |
CRM synchronization when you do not know whether the contact exists. |
delete |
404 error. |
Deletes the contact (200). |
Contact removal. |
get |
404 error. |
Returns the contact (200). |
Single lookup. |
list |
— | — | Text search (requires search). |
Important:
deletepermanently removes the contact. Conversation, message and campaign history is kept (it is linked by phone number), but the contact's name, notes, tags and attributes are no longer available.
Response examples¶
Create or update (create, update, upsert)
{
"success": true,
"status": "created",
"contact": {
"phone": "5491112345678",
"name": "Juan Perez",
"customer_id": "CLI-27544",
"notes": "Home plan customer",
"tags": ["VIP"],
"attributes": { "zone": "Almafuerte", "plan": "fiber_500" }
}
}
status is either created or updated, depending on what happened.
Lookup (get)
{
"success": true,
"contact": {
"phone": "5491112345678",
"name": "Juan Perez",
"customer_id": "CLI-27544",
"notes": "Home plan customer",
"tags": ["VIP"],
"attributes": { "zone": "Almafuerte", "plan": "fiber_500" }
}
}
Search (list)
{
"success": true,
"total": 1,
"limit": 50,
"offset": 0,
"contacts": [
{
"phone": "5491112345678",
"name": "Juan Perez",
"customer_id": "CLI-27544",
"notes": "Home plan customer",
"tags": ["VIP"],
"attributes": { "zone": "Almafuerte", "plan": "fiber_500" }
}
]
}
Delete (delete)
{
"success": true,
"status": "deleted",
"phone": "5491112345678"
}
Errors¶
On error, the response includes "success": false and a message in error:
{ "success": false, "error": "Contact not found" }
| HTTP code | Message (error) |
Cause |
|---|---|---|
400 |
Missing parameters - Token is required |
token was not sent (or the JSON is invalid). |
400 |
Invalid action. Allowed values: create, update, upsert, delete, get, list |
action is missing or unknown. |
400 |
Missing parameters - Phone is required |
phone is missing or contains no digits. |
401 |
Invalid token |
The token does not belong to any company. |
404 |
Contact not found |
update, get or delete on a phone that does not exist. |
409 |
A contact with that phone number already exists |
create on a phone that is already registered. |
422 |
The name field is required to create a contact |
create or upsert of a new contact without name. |
422 |
name cannot be empty |
update with an empty name. |
422 |
attributes must be a JSON object |
attributes is not an object. |
422 |
tags must be an array of tag names |
tags is not an array. |
422 |
Unknown tags: <list> |
One or more tags do not exist in Kewbot. |
422 |
search is required (minimum 3 characters) |
list without search or with fewer than 3 characters. |
500 |
Internal error |
Unexpected server error. |
Best practices¶
- To synchronize contacts with a CRM, prefer
upsert. - Use
getfor single lookups and avoid repeatinglistperiodically. - Keep the token on the customer's server; never in mobile apps or in code reachable from the browser.