testmonitor / activecampaign

This package provides a PHP SDK for the ActiveCampaign API (v3).
MIT License
20 stars 18 forks source link

Fatal error: Uncaught Error: Class 'ActiveCampaign' not found in... #26

Closed zebrastribe closed 2 years ago

zebrastribe commented 3 years ago

Hi

I have some problems with using the wrapper:

First the path in: require DIR.'/../vendor/autoload.php'; does not find the autoload.php file

So I changed it to: require DIR . '/vendor/autoload.php';

define('ACTIVE_CAMPAIGN_URL','https://xxx.api-us1.com'); define('ACTIVE_CAMPAIGN_KEY','xxx');

$activeCampaign = new ActiveCampaign(ACTIVE_CAMPAIGN_URL, ACTIVE_CAMPAIGN_KEY);

The ActiveCampaign Class is not found...

why?

gavin310 commented 2 years ago

This is old, but maybe this can help someone else. For some reason this wrapper doesn't load the classes in composer's autoloader, so you have to manually require the src/ActiveCampaign.php file. Here's a trimmed down version of what I'm doing in WordPress, which seems to work fine.

use TestMonitor\ActiveCampaign\ActiveCampaign;
use TestMonitor\ActiveCampaign\Resources\Contact;

require( get_template_directory() . '/lib/vendor/testmonitor/activecampaign/src/ActiveCampaign.php' );

$ac = new ActiveCampaign( ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY );
$contact = $ac->findOrCreateContact( $email, $first_name, $last_name, $phone );
if ( $contact instanceof Contact ) {
    $contact->subscribe( 123 ); // List ID to add contact to
}
stefanius commented 2 years ago

Thank you for the reported issue. I will close it for now, if you want to change something feel free to start a new PR.