adding a new contact


adding a new contact

i'm using the php library to add a new contact to a's my code:


require_once 'src/Ctct/autoload.php';

use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;


//my credentials
    $username = '';
    $apiKey = '';
    $consumerSecret = '';
    $apipass = '';       
    $ConstantContact = new ConstantContact("basic", $apiKey, $username, $apipass);

    $Contact = new Contact();
    $Contact->emailAddress = "";
    $Contact->firstName = "ftest";
    $Contact->lastName = "ltest";
    $Contact->lists = array('$username/lists/1');

    $NewContact = $ConstantContact->addContact($Contact);
        mail('','contact addeded','success');

        mail('','contact not addeded','failure');


but when i run the above code, i get the error:


Catchable fatal error: Argument 2 passed to Ctct\ConstantContact::addContact() must be an instance of Ctct\Components\Contacts\Contact, none given, called in /home/masterss/public_html/projects/constantcontactapi/contact.php on line 28 and defined in /home/masterss/public_html/projects/constantcontactapi/src/Ctct/ConstantContact.php on line 153


seems to be a problem when  addContact() is called..why i'm i getting the above error?..any assistance would be much appreciated


Hi Georgette,


It looks like you are mixing an old and new PHP library in the code you provided. 


This is the PHP SDK method to use to add or update a contact. 


The v2 API does not accept the basic authentication method. In order to get an OAuth 2.0 access token (which is required for the v2 API) follow the instructions here.




Rich Marcucella
Sr. Technical Writer, Content Developer
Web Services Team
Developer Portal

View API documentation, code samples, get your API key.

Visit Page