relyz/active-campaign-sdk
Composer 安装命令:
composer require relyz/active-campaign-sdk
包简介
PHP SDK for the ActiveCampaign API v3
README 文档
README
PHP wrapper for the ActiveCampaign API v3. Returns typed models, retries on rate limits, and handles pagination.
This is an unofficial SDK. Built and maintained by relyz AG.
Note: This SDK targets ActiveCampaign API v3 exclusively. The API version prefix (
/api/3/) is not configurable.
Requirements
- PHP 8.1+
- Guzzle 7.0+
Installation
composer require relyz/active-campaign-sdk
Usage
$ac = new ActiveCampaign\Client( url: 'https://youraccountname.api-us1.com', apiKey: 'your-api-key', );
Or set the ACTIVE_CAMPAIGN_API_URL and ACTIVE_CAMPAIGN_API_KEY environment variables (via .env, Docker, export, etc.) and omit the arguments:
$ac = new ActiveCampaign\Client();
Create a contact
$contact = $ac->contacts()->create( email: 'jane@example.com', firstName: 'Jane', lastName: 'Doe', ); // $contact is a typed Contact model echo $contact->id;
For most methods there are simplified versions (like the one above) that should cover most use cases. In case some parameters are missing from the simplified version, there is always a *Raw method available, to which you can just pass an array with all the parameters that the API endpoints accepts.
$contact = $ac->contacts()->createRaw([ 'email' => 'jane@example.com', 'firstName' => 'Jane', 'lastName' => 'Doe', ]);
Error Handling
The SDK throws typed exceptions for different HTTP error scenarios:
use ActiveCampaign\Exceptions\AuthenticationException; use ActiveCampaign\Exceptions\NotFoundException; use ActiveCampaign\Exceptions\ValidationException; use ActiveCampaign\Exceptions\RateLimitException; use ActiveCampaign\Exceptions\ActiveCampaignException; try { $contact = $ac->contacts()->get(999); } catch (NotFoundException $e) { // 404 — resource not found echo $e->getMessage(); print_r($e->getResponseBody()); // parsed JSON from API } catch (ValidationException $e) { // 422 — validation failed print_r($e->getResponseBody()['errors'] ?? []); } catch (AuthenticationException $e) { // 401/403 — invalid or missing API key } catch (RateLimitException $e) { // 429 — rate limit exceeded (after retries exhausted) } catch (ActiveCampaignException $e) { // All other API errors (5xx, etc.) }
All exceptions extend ActiveCampaignException, which extends RuntimeException. Every exception provides getResponseBody() returning the parsed API response as an array.
Pagination
Basic Listing
$result = $ac->contacts()->list(['limit' => 50, 'offset' => 0]); foreach ($result->data as $contact) { echo $contact->email; } echo $result->meta->total; // Total records available
Lazy Pagination
Use paginate() for automatic lazy-loading across all pages:
foreach ($ac->contacts()->paginate(limit: 100) as $contact) { echo $contact->email; // Fetches next page automatically }
Rate Limiting
The SDK automatically retries requests that receive a 429 Too Many Requests response, respecting the Retry-After header. By default, it retries up to 3 times using sleep().
To customize retry behavior (e.g., for non-blocking strategies or logging):
$ac = new Client( maxRetries: 5, );
For advanced control, provide a custom retry callback via the HTTP client:
use ActiveCampaign\Http\Client as HttpClient; $httpClient = new HttpClient( retryDelay: function (int $retryAfter, int $attempt): void { usleep($retryAfter * 1_000_000); }, );
Custom HTTP Client
The SDK accepts any PSR-18 compatible HTTP client:
use ActiveCampaign\Client; $ac = new Client( httpClient: $yourPsr18Client, );
By default, the SDK uses Guzzle 7.
Environment Variables
The SDK reads these environment variables as fallbacks when constructor arguments are not provided:
| Variable | Description |
|---|---|
ACTIVE_CAMPAIGN_API_URL |
Your ActiveCampaign API URL |
ACTIVE_CAMPAIGN_API_KEY |
Your ActiveCampaign API key |
// Uses environment variables automatically $ac = new Client();
Available Resources
Each resource is a method on the client object.
Core: contacts(), deals(), tags(), lists(), accounts(), automations(), campaigns(), webhooks(), customFields(), notes(), forms(), segments(), users(), addresses()
Deals: pipelines(), dealStages(), dealCustomFields(), dealCustomFieldValues(), dealRoles(), dealTasks(), dealTaskTypes(), dealTaskOutcomes()
Accounts: accountContacts(), accountCustomFields(), accountCustomFieldValues()
Contact fields: fieldValues(), fieldOptions()
Communication: messages(), scores()
Admin: groups(), calendarFeeds(), brandings(), savedResponses(), templates(), settings()
E-Commerce: connections(), ecomCustomers(), ecomOrders(), ecomOrderProducts()
Tracking: eventTracking(), siteTracking()
Custom Objects: customObjectSchemas(), customObjectRecords($schemaId)
Bugs
Report issues at GitHub Issues.
License
MIT
relyz/active-campaign-sdk 适用场景与选型建议
relyz/active-campaign-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「sdk」 「crm」 「activecampaign」 「email-marketing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 relyz/active-campaign-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 relyz/active-campaign-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 relyz/active-campaign-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
ABsurge PHP SDK for feature flags and A/B testing
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-26