targito/targito-api
A PHP client for the Targito marketing automation API, making it easy to manage contacts, lists, campaigns, and events from Laravel or any Composer-based application. Simplify email/SMS marketing integrations with a straightforward SDK.
composer require targito/targito-api
This is a plain PHP SDK, not a Laravel package — expect no service provider, facade, or auto-discovery. First steps:
src/ before anything else. With a single-digit star count and one release (May 2023), the source is the documentation. Identify the main client class (typically Targito\Api\...) and its constructor signature — it usually takes an account identifier plus an API key/token.config/services.php:'targito' => [
'account_id' => env('TARGITO_ACCOUNT_ID'),
'api_key' => env('TARGITO_API_KEY'),
'base_url' => env('TARGITO_BASE_URL', 'https://api.targito.com'),
],
TargitoServiceProvider so you inject it rather than new-ing it in controllers:$this->app->singleton(TargitoClient::class, fn ($app) => new TargitoClient(
config('services.targito.account_id'),
config('services.targito.api_key'),
));
First use case: a newsletter signup. On Registered or a form submission, call the SDK's contact/upsert method to add the email to a Targito list. That validates credentials, base URL, and error handling in one small, low-risk path before you build anything larger.
Wrap, don't sprinkle. The SDK will leak into controllers quickly if you call it directly. Create App\Services\Targito\TargitoService that exposes intent-named methods (subscribeContact, unsubscribeContact, syncContact) and hides the SDK types. This is your seam for testing and for swapping the SDK if it stalls.
Queue the calls. Every Targito call is a network round trip. Push contact syncs onto a job:
SyncContactToTargito::dispatch($user)->onQueue('integrations');
Use $tries = 3, backoff = [10, 60], and a failed() handler that logs the payload. Never let a marketing-platform outage break registration.
Event-driven sync. Wire domain events (Registered, ProfileUpdated, OrderPlaced) to listeners that translate your model into the SDK's contact payload. Keep the mapping in one place — a ContactMapper or a toTargito() method on a DTO — so field renames in Targito are a one-file change.
Bulk imports. For backfills, chunk your Eloquent query (->chunkById(500)) and check whether the SDK has a batch/bulk endpoint. If it only has single-record calls, wrap each in rescue() inside a job so one bad email doesn't fail the whole batch, and throttle with RateLimited or usleep.
Testing. Since there's no built-in fake, define an interface (ContactGateway) implemented by the SDK adapter and a FakeContactGateway in tests. In feature tests, $this->swap(ContactGateway::class, $fake) and assert on recorded calls. For integration tests, use Http::fake() — the SDK almost certainly uses Guzzle under the hood, but confirm; if it uses its own transport, you may need to point base_url at a local stub server.
Webhooks. If Targito supports outbound webhooks, register a route and verify the signature/token per their docs. Treat webhook handlers like any external input: validate, queue, respond 200 fast.
"targito/targito-api": "1.0.*") so an unexpected tag doesn't break you, and keep your TargitoService wrapper thin enough to reimplement over Laravel's Http client in an afternoon if needed.guzzlehttp/guzzle:^6 or ^7.0 narrowly, which can clash with your Laravel version. If Composer refuses, check composer why-not guzzlehttp/guzzle first; a fork with a widened constraint is usually cleaner than downgrading Laravel.\Exception or a single SDK exception. Catch broadly at your service boundary, log getMessage() plus the request context, and translate into your own TargitoException. Without this, a 401 (bad key) and a 429 (rate limit) look identical in logs.base_url and account ID once at boot in non-production, and sanity-check credentials with a single GET during deployment.debug => true handler or wrap with Laravel's Http::withOptions(['debug' => ...]) if you fork. Also log the request payload (redact emails/keys) before the call; the most common bug is a field-name mismatch that Targito rejects with a vague message.APP_ENV=local. Contact-data mistakes are hard to undo.How can I help you explore Laravel packages today?