Search by

cuongcds / octivo-php

cuongcds

PHP SDK for the Octivo CRM Lead capture API

Package info

github.com/cuongcds/octivo-php

pkg:composer/cuongcds/octivo-php

Statistics

Installs: 37

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-09-17 16:36 UTC

This package is auto-updated.

Last update: 2026-09-17 16:45:17 UTC


README

PHP SDK for the Octivo CRM API. Lead capture is the first resource covered — a public, unauthenticated endpoint used by landing pages/widgets to create a row in crm_leads, scoped to a channel via its public source_id. More Octivo CRM resources will be added to this SDK over time.

Install

composer require cuongcds/octivo-php

Usage

use Octivo\Crm\OctivoClient;
use Octivo\Crm\LeadRequest;
use Octivo\Crm\Exception\ValidationException;
use Octivo\Crm\Exception\ApiException;

// baseUrl defaults to https://octivo.cloud; pass one to target a different environment.
$client = new OctivoClient('your-channel-source-id');

$request = LeadRequest::create()
    ->withName('Nguyen Van A')
    ->withEmail('nguyenvana@example.com')
    ->withPhone('0912345678')
    ->withMeta('usecase', 'chatbot_sales')
    ->withMeta('utm_source', 'facebook-ads')
    ->withMeta('utm_campaign', 'spring-promo');

try {
    $result = $client->createLead($request);
    // $result->id, $result->success
} catch (ValidationException $e) {
    // neither email nor phone was provided
} catch (ApiException $e) {
    // API rejected the request: $e->getStatusCode(), $e->getMessage(), $e->getResponseBody()
}

At least one of email/phone must be provided; name falls back server-side to the email/phone when omitted. Any extra field added via withMeta()/withMetaFields() is stored server-side in the lead's meta JSON column.

Optional reCAPTCHA v3

If the target server has recaptcha_secret_key configured, pass a client-generated token (action create_lead) via withRecaptchaToken(). It's ignored otherwise.

Custom HTTP transport

The client uses a cURL-based transport by default. Swap it by implementing Octivo\Crm\Http\HttpClientInterface and passing it as the third constructor argument to OctivoClient.

Examples

Runnable scripts are in examples/:

composer install
OCTIVO_SOURCE_ID=your-channel-source-id php examples/create-lead.php

Errors

  • Octivo\Crm\Exception\ValidationException — thrown client-side before any request is sent (missing email and phone).
  • Octivo\Crm\Exception\ApiException — thrown when the API responds with an error (invalid source_id, invalid phone/email, reCAPTCHA failure). Carries getStatusCode() and getResponseBody().
  • Octivo\Crm\Exception\OctivoException — base class, also thrown on transport failures (network error, timeout).

Reference

See docs/crm-lead-api.postman_collection.json for the underlying HTTP API this SDK wraps.