firewards / convertkit-php-api
Simple access interface to ConvertKit's web API.
Requires
- convertkit/convertkitapi: dev-master
This package is auto-updated.
Last update: 2024-11-19 23:25:52 UTC
README
Unofficial ConvertKit PHP API for v3.
This package makes it simple to access ConvertKit's web API. Checkout https://developers.convertkit.com for more information on ConvertKit's API.
Install
Via Composer
$ composer require firewards/convertkit-php-api
Requirements
The following versions of PHP are supported.
- PHP 5.6
- PHP 7.0
- PHP 7.1
- PHP 7.2
- PHP 7.3
API Key
All API calls require an API Key. You can find your API Key in the ConvertKit Account page.
API Secret
Some API calls require an API Secret. All calls that require the api key will also work with the api secret, there's no need to use both. This key grants access to sensitive data and actions on your subscribers.
Usage
Start by using ConvertKit API and creating an instance with your ConvertKit API key
$api = new \Firewards\Apis\ConvertKit($api_key, $api_secret);
Examples
Get all Subscribers
Get all subscribers using pagination.
$i = 0; while ($subscribers = $api->getSubscribers($i++)) { if (!isset($subscribers->subscribers) || count($subscribers->subscribers) === 0) { break; } var_dump($subscribers); }
Get all Custom Fields
$customFields = $api->getCustomFields();
Create a Custom Field
$lastNameField = $api->createCustomField('last_name');
Update subscriber
Updates a subscriber and adds info to a custom field 'last_name'.
$subscriberId = '1234'; $lastNameField = $api->updateSubscriber($subscriberId, ['last_name' => 'Stücken']);
Get Tags
Retrieve all tags.
$tags = $api->getTags();
Add Subscriber to Tag
Adds a subscriber to a specific tag.
$added = $api->addSubscriberToTag($tagId, $email);
Subscribe to a form
Add a subscriber to a form. The $subscribed
response will be an object.
$tag_id = '99999'; // This tag must be valid for your ConvertKit account. $options = [ 'email' => 'test@test.com', 'name' => 'Full Name', 'first_name' => 'First Name', 'tags' => $tag_id, 'fields' => [ 'phone' => 134567891243, 'shirt_size' => 'M', 'website_url' => 'testurl.com' ] ]; $subscribed = $api->form_subscribe($this->test_form_id, $options);
Get Subscriber ID
Get the ConvertKit Subscriber ID for a given email address.
$subscriber_id = $api->get_subscriber_id( $email );
Get Subscriber
Get subscriber data for a ConvertKit Subscriber.
$subscriber = $api->get_subscriber( $subscriber_id );
Get Subscriber Tags
Get all tags applied to a Subscriber.
$subscriber_tags = $api->get_subscriber_tags( $subscriber_id );
Add Tag to a Subscriber
Apply a tag to a Subscriber.
$tag_id = '99999'; // This tag must be valid for your ConvertKit account. $api->add_tag(tag_id, [ 'email' => 'test@test.com' ]);
Rate limiting
Please note that ConvertKit is rate limiting requests by 120 requests per minute. If your request rate exceeds the limit, ConvertKit PHP Api will throw a RateLimitExcededException.
License
The MIT License (MIT). Please see License File for more information.
Sponsor
This package is sponsored by www.firewards.com, Firewards makes it easy to setup a referral and rewards program for your email list and newsletter.