icontact add contact PHP API

903 Views Asked by At

I am trying to use PHP Api from iContact to store a contact. I have registered the account, I am using the iContactApi.php from GitHub provided by iContact.

My sourcecode looks like thisL

// Load the iContact library
require_once('ws/iContactApi.php');

// Give the API your information
iContactApi::getInstance()->setConfig(array(
    'appId'       => 'myappID', 
    'apiPassword' => 'myuser', 
    'apiUsername' => 'mypass'
));

// Store the singleton
$oiContact = iContactApi::getInstance();
// Try to make the call(s)
//try {
    //  are examples on how to call the  iContact PHP API class

    // Create a contact
    var_dump($oiContact->addContact('[email protected]', null, null, 'Joe', 'Shmoe', null, '123 Somewhere Ln', 'Apt 12', 'Somewhere', 'NW', '12345', '123-456-7890', '123-456-7890', null));

//}

I get the following error:

Fatal error: Uncaught exception 'Exception' with message 'Errors have occurred and the system cannot continue. Use getErrors() for details.' in C:\xampp\htdocs\clydebutcher\ws\iContactApi.php:482 Stack trace: #0 C:\xampp\htdocs\clydebutcher\ws\iContactApi.php(1096): iContactApi->makeCall('/a/', 'get', NULL, 'accounts') #1 C:\xampp\htdocs\clydebutcher\ws\iContactApi.php(212): iContactApi->setAccountId() #2 C:\xampp\htdocs\clydebutcher\mdl-newsletter-save.php(130): iContactApi->addContact('[email protected]', NULL, NULL, 'Joe', 'Shmoe', NULL, '123 Somewhere L...', 'Apt 12', 'Somewhere', 'NW', '12345', '123-456-7890', '123-456-7890', NULL) #3 C:\xampp\htdocs\clydebutcher\mdl.php(14): include('C:\xampp\htdocs...') #4 C:\xampp\htdocs\clydebutcher\index.php(13): include('C:\xampp\htdocs...') #5 {main} thrown in C:\xampp\htdocs\clydebutcher\ws\iContactApi.php on line 482

Am I making something wrong?

1

There are 1 best solutions below

0
On

You want to use the getError() method from the iContact API to find out more information about what happened.

  try {
    // Give the API your information.
    iContactApi::getInstance()->setConfig(array(
      'appId'       => 'myid',
      'apiPassword' => 'mypassword',
      'apiUsername' => 'mysecret',
    ));

    // Store the singleton
    $oiContact = iContactApi::getInstance();


    // Create a contact
    var_dump($oiContact->addContact('[email protected]', null, null, 'Joe', 'Shmoe', null, '123 Somewhere Ln', 'Apt 12', 'Somewhere', 'NW', '12345', '123-456-7890', '123-456-7890', null));

  }
  catch (Exception $e) {
    print_r($oiContact->getErrors();
  }