Bad request when trying to addContact()?

Regular Participant

Bad request when trying to addContact()?

Hi there.  I'm using the v2 PHP API (dev-development branch for up-to-date guzzle support).  When trying to addContact(), I'm getting a 'bad request' exception.  I've been trying to debug for hours, but cannot find a solution.


Here's my code:



Here's the output of that var_dump($contact):


And here's the error:


Any help would be appreciated!




I've reviewed your code as well as the contents of the payload you're sending and things seem to be in order here. Based on the error response, it seems like something is coming out invalid in the payload that's coming through. The best way to troubleshoot this is to look at the detailed error returned from the API.


If you add a try-catch block to your code around the AddContact API call, then you can catch the CtctException and use the getErrors() method on the exception to get a list of errors in a key-> message format.


For example:


try {
  // Add Contact code on this line
} catch (CtctException $ex) {

This would give a detailed look at the errors returned, which should include a specific reason why the request failed. If you have any problems or questions, please let me know!



Elijah G.
API Support Engineer

Hi Elijah, Thank you for the reply.  With a try-catch block, I get the following:


try catch


Looking into the addContact() method within ContactService class, $actionByContact parameter should accept a simple boolean.  Not sure why it's rejecting this parameter.  Any thoughts?



Sorry about my delay on this, I had to take a good bit of time and really get into the code to figure out what was going on. It looks like in the course of fixing some other minor bugs in the SDK, we accidentally introduced a new bug (Thank you for reporting this!) into the developmentbranch that causes the action_by_visitor parameter to be set incorrectly. While we do hope to have a fix for this into the development branch very soon, there may be other issues that we haven't yet resolved.


In order to make sure you have the most stable code, I would generally advise using the master branch if you wish to pull the code directly, or to download the latest release of the SDK (Currently 2.1.2).


If you have any questions for me, please let me know!



Elijah G.
API Support Engineer

Thank you for reply.  Problem is, if I pull in either of these versions:

"constantcontact/constantcontact": "2.1.*"
"constantcontact/constantcontact": "dev-master"

Then composer refuses to install due to a guzzle version conflict with Laravel, the app framework I'm using.  When needing to use Laravel's mail functionality (which I am), Laravel documention instructs me to pull in:

"guzzlehttp/guzzle": "~5.3|~6.0"

Yet any stable version of Constant Contact's PHP-SDK is constrained to an old version of guzzle:

"guzzlehttp/guzzle": "^5.1.0"

Not sure what I can do here?

Hi Carl,


I think I'm using a similar version of the PHP SDK as you. Are you sure you should be calling into a separate contactService for the addContact call? I have something like this that doesn't get any errors:


//define API Key and access token above. Also set contact values.

$cc = new ConstantContact(APIKEY);

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

I think later versions of the SDK than you're using split the SDK up more so that you might have to call services rather than just ConstantContact like I am above. The version you downloaded should have had an example file that showed the correct usage for the one you downloaded.


Best Regards,

Shannon Wallace

Partner API Support Engineer

I should've mentioned, my name is Jesse :)  Carl is the name on this Constant Contact account, and I'm doing web development work with him.


Anyway, if I try to pull in an older version of the PHP-SDK, you're right in that I wouldn't need to go through contactService object to addContact().  However, I cannot pull in an older version of the SDK without composer dependency conflicts around the old version of guzzle that the SDK used back then.

Hi Jesse,


Oh, I see. I believe I avoided using guzzle entirely in my use of the older PHP SDK. Maybe you can use my version, since it's a standalone version that doesn't require the use of guzzle or composer.


Email me ATTN Shannon at and reference this thread--I'll give you a zip file of my version.


EDIT: Quick note that my version does have a composer.php file, but doesn't require its use. I'm not using composer even though the file is present. 


Best Regards,

Shannon Wallace

Partner API Support Engineer

Ohhh it looks like development branch fixed my issue in this commit!  Going to fork development branch now and pull forked repo until all these changes are merged into master and tagged as stable.  I can't rely on a changing development branch if new bugs could be introduced without notice.  Thank you all for your help & replies here :)

Hi Jesse,


Great, I'm glad that solved it. Thanks for letting us know. Personally I also keep my project static to avoid conflicts (I don't pull changes from the master). I wouldn't anticipate you needing to make changes any time soon since the underlying API that the SDK calls is very stable.


Best Regards,

Shannon Wallace

Partner API Support Engineer

Yes I normally like to lock external API packages to an explicit git tag for that reason.  Problem is, there's no working stable version tagged I can lock to without guzzle dependency conflicts in my app.  Like you said, I'd either need to go really old with the SDK (to bypass guzzle), or lock myself to this specific commit on development branch, since I've tested and know it works.  That said, I just found out I can dump my fork and lock to this specific commit:


"constantcontact/constantcontact": "dev-development#d002af0ac2f777bde569e0d0ba567e0133f525ba"


Thanks again!

Developer Portal

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

Visit Page