PHP code example of firewards / convertkit-php-api

1. Go to this page and download the library: Download firewards/convertkit-php-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

firewards / convertkit-php-api example snippets


$api = new \Firewards\Apis\ConvertKit($api_key, $api_secret);

$i = 0;
while ($subscribers = $api->getSubscribers($i++))
{
    if (!isset($subscribers->subscribers) || count($subscribers->subscribers) === 0)
    {
        break;
    }
    
    var_dump($subscribers);
}

$customFields = $api->getCustomFields();

$lastNameField = $api->createCustomField('last_name');

$subscriberId = '1234';
$lastNameField = $api->updateSubscriber($subscriberId, ['last_name' => 'Stücken']);

$tags = $api->getTags();

$added = $api->addSubscriberToTag($tagId, $email);

$tag_id = '99999'; // This tag must be valid for your ConvertKit account.

$options = [
			'email'      => '[email protected]',
			'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);

$subscriber_id = $api->get_subscriber_id( $email );

$subscriber = $api->get_subscriber( $subscriber_id );

$subscriber_tags = $api->get_subscriber_tags( $subscriber_id );

$tag_id = '99999'; // This tag must be valid for your ConvertKit account.
$api->add_tag(tag_id, [
			'email' => '[email protected]'
		]);
 bash
$ composer