Customers API
Manage customer records for your business transactions. Customers are the individuals or businesses you sell to.
Overview
The Customers API allows you to:
- List customers with filtering and pagination
- Create new customer records
- Search customers by name, TIN, or phone number
- Update customer information
- View customer transaction history
- Delete customer records
Customer Structure
Key Fields
| Field | Description |
|---|---|
customer_no | Unique customer identifier/code |
custNm | Customer name (individual or business) |
tin | Tax Identification Number (for B2B transactions) |
phone | Contact phone number |
email | Contact email address |
address | Physical or postal address |
branch_id | Branch this customer belongs to |
is_active | Whether the customer is active |
TIN Format
| Format | Example | Description |
|---|---|---|
PXXXXXXXXXC | P000123456X | Personal TIN (11 characters) |
AXXXXXXXXXX | A000123456Z | Business/Company TIN |
List Customers
Get all customers for your account.
/api/v1/customersList Customers
Retrieve all customers for your client account with optional filtering.
branch_idFilter customers by branch ID
searchSearch by name, TIN, or phone number
statusFilter by status (active, inactive)
pagePage number for pagination
per_pageItems per page (max 100)
Response
Status: 200 OK
{
"status": "success",
"data": [
{
"id": 1,
"customer_no": "CUST001",
"name": "ABC Trading Ltd",
"tin": "P000123456X",
"phone": "+254712345678",
"email": "info@abctrading.co.ke",
"address": "Moi Avenue, Nairobi",
"branch_id": "00",
"is_active": true,
"total_transactions": 45,
"created_at": "2025-01-01T10:00:00Z"
},
{
"id": 2,
"customer_no": "CUST002",
"name": "Jane Wanjiku",
"tin": null,
"phone": "+254722345678",
"email": "jane@email.com",
"address": "Westlands, Nairobi",
"branch_id": "00",
"is_active": true,
"total_transactions": 12,
"created_at": "2025-01-05T10:00:00Z"
}
],
"meta": {
"total": 150,
"per_page": 25,
"current_page": 1,
"last_page": 6,
"timestamp": "2025-01-15T14:30:00Z"
}
}Create Customer
Register a new customer for your account.
/api/v1/customersCreate Customer
Register a new customer with their details.
Field Descriptions
| Field | Type | Required | Description |
|---|---|---|---|
branch_id | string | Yes | Branch ID this customer belongs to (e.g., “00”) |
customer_no | string | Yes | Unique customer identifier/code (max 50 chars) |
custNm | string | Yes | Customer name - individual or business (max 255 chars) |
tin | string | No | Tax Identification Number (format: P000XXXXXXX) |
phone | string | No | Contact phone number (max 50 chars) |
email | string | No | Contact email address (max 255 chars) |
address | string | No | Physical or postal address (max 500 chars) |
metadata | object | No | Additional custom metadata |
Response
Status: 201 Created
{
"status": "success",
"message": "Customer created successfully",
"data": {
"id": 3,
"customer_no": "CUST003",
"name": "XYZ Enterprises",
"tin": "P000789012Y",
"phone": "+254733345678",
"email": "contact@xyz.co.ke",
"address": "Industrial Area, Nairobi",
"branch_id": "00",
"is_active": true,
"created_at": "2025-01-17T10:00:00Z"
},
"meta": {
"timestamp": "2025-01-17T10:00:00Z",
"request_id": "req_abc123"
}
}Get Customer Details
Retrieve details of a specific customer including their transaction history.
/api/v1/customers/{customerId}Get Customer Details
Retrieve detailed information about a specific customer including transaction summary.
customerId*Customer ID
Response
Status: 200 OK
{
"status": "success",
"data": {
"id": 1,
"customer_no": "CUST001",
"name": "ABC Trading Ltd",
"tin": "P000123456X",
"phone": "+254712345678",
"email": "info@abctrading.co.ke",
"address": "Moi Avenue, Nairobi",
"branch_id": "00",
"branch_name": "Head Office",
"is_active": true,
"metadata": {},
"transaction_summary": {
"total_transactions": 45,
"total_sales_amount": 1250000.00,
"this_month_transactions": 8,
"last_transaction_at": "2025-01-14T16:30:00Z"
},
"recent_transactions": [
{
"id": "uuid-123",
"type": "sales",
"invoice_no": "INV-045",
"amount": 15000.00,
"status": "success",
"created_at": "2025-01-14T16:30:00Z"
}
],
"created_at": "2025-01-01T10:00:00Z",
"updated_at": "2025-01-14T16:30:00Z"
}
}Status: 404 Not Found
{
"status": "error",
"message": "Customer not found"
}Update Customer
Update an existing customer’s information.
/api/v1/customers/{customerId}Update Customer
Update customer information. All fields are optional - only provided fields will be updated.
customerId*Customer ID
Response
Status: 200 OK
{
"status": "success",
"message": "Customer updated successfully",
"data": {
"id": 1,
"customer_no": "CUST001",
"name": "ABC Trading Ltd - Updated",
"tin": "P000123456X",
"phone": "+254712999999",
"email": "updated@abctrading.co.ke",
"address": "New Location, Westlands, Nairobi",
"branch_id": "00",
"is_active": true,
"updated_at": "2025-01-17T15:00:00Z"
}
}Delete Customer
Delete a customer (soft delete).
/api/v1/customers/{customerId}Delete Customer
Soft delete a customer. Historical transaction records with this customer are preserved.
customerId*Customer ID to delete
Response
Status: 200 OK
{
"status": "success",
"message": "Customer deleted successfully"
}Note: Historical transaction records with this customer are preserved for audit purposes. The customer will no longer appear in search results or dropdown lists.
Search Customers
Search for customers by name, TIN, or phone number.
/api/v1/customers/searchSearch Customers
Quick search endpoint for finding customers. Useful for autocomplete in sales forms.
q*Search query (min 2 characters)
branch_idLimit search to specific branch
limitMaximum results to return (default 10, max 50)
Response
Status: 200 OK
{
"status": "success",
"data": [
{
"id": 1,
"customer_no": "CUST001",
"name": "ABC Trading Ltd",
"tin": "P000123456X",
"phone": "+254712345678"
},
{
"id": 5,
"customer_no": "CUST005",
"name": "ABC Supplies",
"tin": "P000456789Z",
"phone": "+254745678901"
}
],
"meta": {
"count": 2,
"query": "ABC"
}
}Get Customer Transactions
Retrieve all transactions for a specific customer.
/api/v1/customers/{customerId}/transactionsGet Customer Transactions
Retrieve transaction history for a specific customer with pagination.
customerId*Customer ID
typeFilter by transaction type (sales, purchases)
from_dateStart date (YYYY-MM-DD)
to_dateEnd date (YYYY-MM-DD)
pagePage number
Response
Status: 200 OK
{
"status": "success",
"data": [
{
"id": "uuid-123",
"type": "sales",
"invoice_no": "INV-045",
"total_amount": 15000.00,
"tax_amount": 2400.00,
"status": "success",
"branch_id": "00",
"created_at": "2025-01-14T16:30:00Z"
},
{
"id": "uuid-122",
"type": "sales",
"invoice_no": "INV-040",
"total_amount": 8500.00,
"tax_amount": 1360.00,
"status": "success",
"branch_id": "00",
"created_at": "2025-01-10T11:00:00Z"
}
],
"meta": {
"total": 45,
"per_page": 25,
"current_page": 1,
"last_page": 2
}
}Error Responses
400 Bad Request
{
"status": "error",
"message": "Validation failed",
"errors": {
"customer_no": ["The customer_no has already been taken."],
"tin": ["The tin format is invalid."]
}
}404 Not Found
{
"status": "error",
"message": "Customer not found"
}409 Conflict
{
"status": "error",
"message": "Customer with this customer_no already exists in this branch"
}Code Examples
JavaScript
const axios = require('axios');
const apiKey = process.env.CTAX_API_KEY;
const baseURL = 'https://c-ushuru.com/api/v1';
// List all customers
const customers = await axios.get(`${baseURL}/customers`, {
headers: { Authorization: `Bearer ${apiKey}` }
});
// Create a new customer
const newCustomer = await axios.post(`${baseURL}/customers`, {
branch_id: '00',
customer_no: 'CUST003',
custNm: 'XYZ Enterprises',
tin: 'P000789012Y',
phone: '+254733345678',
email: 'contact@xyz.co.ke'
}, {
headers: { Authorization: `Bearer ${apiKey}` }
});
// Search customers
const searchResults = await axios.get(`${baseURL}/customers/search`, {
params: { q: 'XYZ', limit: 10 },
headers: { Authorization: `Bearer ${apiKey}` }
});
// Get customer transactions
const transactions = await axios.get(`${baseURL}/customers/1/transactions`, {
params: { type: 'sales', from_date: '2025-01-01' },
headers: { Authorization: `Bearer ${apiKey}` }
});PHP
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://c-ushuru.com/api/v1/',
'headers' => [
'Authorization' => 'Bearer ' . env('CTAX_API_KEY'),
'Content-Type' => 'application/json',
],
]);
// List all customers
$customers = $client->get('customers');
// Create a new customer
$response = $client->post('customers', [
'json' => [
'branch_id' => '00',
'customer_no' => 'CUST003',
'custNm' => 'XYZ Enterprises',
'tin' => 'P000789012Y',
'phone' => '+254733345678',
],
]);
// Search customers
$search = $client->get('customers/search', [
'query' => ['q' => 'XYZ', 'limit' => 10],
]);Python
import requests
import os
api_key = os.environ['CTAX_API_KEY']
base_url = 'https://c-ushuru.com/api/v1'
headers = {'Authorization': f'Bearer {api_key}'}
# List all customers
response = requests.get(f'{base_url}/customers', headers=headers)
customers = response.json()['data']
# Create a new customer
new_customer = requests.post(
f'{base_url}/customers',
json={
'branch_id': '00',
'customer_no': 'CUST003',
'custNm': 'XYZ Enterprises',
'tin': 'P000789012Y',
'phone': '+254733345678',
},
headers=headers
)
# Search customers
search = requests.get(
f'{base_url}/customers/search',
params={'q': 'XYZ', 'limit': 10},
headers=headers
)Best Practices
- Unique Customer Numbers - Use a consistent numbering system (e.g., CUST001, CUST002)
- Record TIN for B2B - Always capture TIN for business customers
- Branch Assignment - Assign customers to the branch they primarily transact with
- Regular Updates - Keep customer contact information current
- Use Search - Leverage the search endpoint for quick lookups during sales
- Walk-in Customers - Create a generic “Walk-in” customer for cash sales without customer details
Related Endpoints
- Sales API - Create sales with customer information
- Branches API - Manage customer branches
- Transactions API - View all transactions
- Reports API - Generate customer reports