CodeIgniter WhatsApp API Integration
Integrate WhatsApp Business API with CodeIgniter 3 or CodeIgniter 4 using PHP cURL or CURLRequest. Send order confirmations, OTPs, invoices, and payment reminders to customers on WhatsApp from any CI controller. Built for Indian agency-built apps and SMB SaaS still on CodeIgniter.
Why Zaptilo with CodeIgniter?
- Drop-in PHP class — no Composer required (works on shared hosting)
- Pay-as-you-go INR pricing — from ₹0.04 / message at volume
- No monthly subscription, no setup fee, GST-compliant invoicing
- Works with CodeIgniter 3.x and CodeIgniter 4.x
- Compatible with cPanel / shared hosting (most CI deployments)
- India-based support — particularly useful for legacy CI codebases
CodeIgniter 4 — Library + Controller
Library: app/Libraries/Zaptilo.php
<?php
// app/Libraries/Zaptilo.php
namespace App\Libraries;
use Config\Services;
class Zaptilo
{
private string $token;
private string $baseUrl = 'https://web.zaptilo.ai';
public function __construct()
{
$this->token = env('ZAPTILO_API_TOKEN');
}
public function sendTemplate(string $phone, string $name, string $lang, array $bodyValues): array
{
$params = array_map(fn ($v) => ['type' => 'text', 'text' => $v], $bodyValues);
$payload = [
'phone' => $phone,
'template' => [
'name' => $name,
'language' => ['code' => $lang],
'components' => [['type' => 'body', 'parameters' => $params]],
],
];
$client = Services::curlrequest();
$response = $client->post("{$this->baseUrl}/api/send/template", [
'headers' => [
'Authorization' => "Bearer {$this->token}",
'Content-Type' => 'application/json',
],
'json' => $payload,
]);
return json_decode($response->getBody(), true) ?? [];
}
}Controller usage
<?php
// app/Controllers/OrderController.php
namespace App\Controllers;
use App\Libraries\Zaptilo;
class OrderController extends BaseController
{
public function placed()
{
$data = $this->request->getJSON(true);
$zaptilo = new Zaptilo();
$zaptilo->sendTemplate(
'91' . $data['phone'],
'order_confirmation',
'en',
[$data['name'], $data['order_id']]
);
return $this->response->setJSON(['ok' => true]);
}
}CodeIgniter 3 — Library + Controller
Library: application/libraries/Zaptilo.php
<?php
// application/libraries/Zaptilo.php
class Zaptilo
{
private $token;
private $baseUrl = 'https://web.zaptilo.ai';
public function __construct()
{
$CI =& get_instance();
$CI->config->load('zaptilo'); // optional config file with ['token' => '...']
$this->token = $CI->config->item('zaptilo_token');
}
public function sendTemplate($phone, $name, $lang, array $bodyValues)
{
$params = array_map(function ($v) { return ['type' => 'text', 'text' => $v]; }, $bodyValues);
$payload = json_encode([
'phone' => $phone,
'template' => [
'name' => $name,
'language' => ['code' => $lang],
'components' => [['type' => 'body', 'parameters' => $params]],
],
]);
$ch = curl_init("{$this->baseUrl}/api/send/template");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $this->token,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_TIMEOUT => 15,
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
}Controller usage
<?php
// application/controllers/Order.php
class Order extends CI_Controller
{
public function placed()
{
$this->load->library('zaptilo');
$data = json_decode($this->input->raw_input_stream, true);
$this->zaptilo->sendTemplate(
'91' . $data['phone'],
'order_confirmation',
'en',
[$data['name'], $data['order_id']]
);
$this->output
->set_content_type('application/json')
->set_output(json_encode(['ok' => true]));
}
}Use cases for Indian CodeIgniter apps
OTP delivery
Login / signup / 2FA OTPs from CI controllers — replace SMS with WhatsApp.
E-commerce orders
Order placed / shipped / delivered → WhatsApp the customer with PDF invoice.
School ERP communication
Fee reminders, attendance alerts, exam schedules from CodeIgniter school ERPs.
Real estate enquiry
Auto-confirm property visit requests submitted via CI form.
Healthcare clinic ERP
Appointment confirmations + reminders from CI-based clinic management apps.
Custom CRM / business apps
Trigger WhatsApp on any CI controller event — order, invoice, lead capture.
Frequently asked questions
How do I send WhatsApp messages from CodeIgniter?
Use PHP's curl extension or CodeIgniter 4's CURLRequest service to POST to the Zaptilo API endpoint. The full helper is shown above as a Library / Service class — load it once and call sendTemplate() from any controller.
Does Zaptilo work with both CodeIgniter 3 and CodeIgniter 4?
Yes. CI 3 uses cURL directly; CI 4 has the CURLRequest service that's slightly nicer. Both patterns are shown above. Most Indian agency-built apps run CI 3 or CI 4, and the same Zaptilo account serves both.
Is the Composer package zaptilo/whatsapp usable in CodeIgniter?
Yes. CodeIgniter 4 supports Composer natively — just `composer require zaptilo/whatsapp` and use it. CodeIgniter 3 requires manual Composer integration but the package still works once autoload is set up.
What does sending a WhatsApp message from CodeIgniter cost?
About ₹0.04 to ₹0.20 per message in India: Meta's per-conversation rate (varies by category) + Zaptilo's per-message markup. No monthly subscription. INR billing with GST invoice.
Can I receive WhatsApp messages back into CodeIgniter?
Yes — set up a controller endpoint that handles Zaptilo's webhook POSTs. The webhook delivers inbound messages, status updates (sent/delivered/read), and replies. Standard CI controller, just verify the signature.
Will this work on shared hosting / cPanel?
Yes. The Zaptilo integration is a plain HTTPS POST — works on any PHP hosting with cURL enabled (which is essentially all of them). No special server requirements.
Send WhatsApp from your CodeIgniter app
Free signup. INR pricing. GST invoice. Works on shared hosting.
Get Started FreeSee also: Laravel · WordPress · Python · Node.js · All integrations