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
Solved! Go to Solution.
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,
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,
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
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,
That did the trick! Thank you so much!
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article