The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

addorUpdateContact sample code error

SOLVED
Go to solution
Highlighted
Occasional Participant

addorUpdateContact sample code error

I'm trying to automatically add a contact to one of my lists and have started with the addOrUpdateContact sample code for v2 API. I'm getting the following error when I submit the form:

 

Catchable fatal error: Argument 3 passed to Ctct\Services\ContactService::addContact() must be of the type array, boolean given, called in /home/cspacetribeca/public_html/mh/test.php on line 65 and defined in /home/cspacetribeca/public_html/mh/vendor/constantcontact/constantcontact/src/Ctct/Services/ContactService.php on line 131

 

The line referenced is:

$returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact, true);

 

And ContactService.php, on line 131, does ask for an array:

public function addContact($accessToken, Contact $contact, Array $params = array())

 

How do I fix this?

 

Thanks - Joe

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Honored Contributor

Re: addorUpdateContact sample code error

Hi Joe,

 

My apologies on that! I was referencing a current development build rather than the current stable build. For the current version that code is as follows:

$returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact, array("action_by" => "ACTION_BY_VISITOR"));

As a side-note, the ACTION_BY_OWNER and ACTION_BY_VISITOR is a distinction that determines a few things, including if a notification email will be sent about changes to the contact. For an outward facing form, you would want to use ACTION_BY_VISITOR and for an internal form that would instead be used by the account owner, you would use ACTION_BY_OWNER.

 

Let me know if you see any issues!

 

Sincerely,

Elijah G.
API Support Engineer

View solution in original post

4 REPLIES 4
Highlighted
Honored Contributor

Re: addorUpdateContact sample code error

Hi Joe,

 

After looking into this, it looks like the problem here is a bug that we introduced into the sample code for how that last parameter is being sent. The proper formatting is as follows:

 

$returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact, array("action_by" => true));

If you continue to have trouble after this, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Participant

Re: addorUpdateContact sample code error

Hi Elijah,

 

Thanks for the response. I tried replacing that line and now I get the following error:

 

Array
(
    [0] => stdClass Object
        (
            [error_key] => query.param.action_by.invalid
            [error_message] => Invalid action_by parameter. Acceptable values are {'ACTION_BY_OWNER', 'ACTION_BY_VISITOR'}.
        )

)

How do I handle this?

 

Best - Joe

Highlighted
Honored Contributor

Re: addorUpdateContact sample code error

Hi Joe,

 

My apologies on that! I was referencing a current development build rather than the current stable build. For the current version that code is as follows:

$returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact, array("action_by" => "ACTION_BY_VISITOR"));

As a side-note, the ACTION_BY_OWNER and ACTION_BY_VISITOR is a distinction that determines a few things, including if a notification email will be sent about changes to the contact. For an outward facing form, you would want to use ACTION_BY_VISITOR and for an internal form that would instead be used by the account owner, you would use ACTION_BY_OWNER.

 

Let me know if you see any issues!

 

Sincerely,

Elijah G.
API Support Engineer

View solution in original post

Highlighted
Occasional Participant

Re: addorUpdateContact sample code error

That did the trick! Thank you so much!

Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured