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.

Bad request when trying to addContact()?

Highlighted
Occasional Contributor

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:

code

 

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

 

And here's the error:
error

 

Any help would be appreciated!

10 REPLIES 10
Highlighted
Honored Contributor

Re: Bad request when trying to addContact()?

Hello,

 

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) {
   var_dump($ex->getErrors());
}

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!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Contributor

Re: Bad request when trying to addContact()?

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?

Highlighted
Honored Contributor

Re: Bad request when trying to addContact()?

Hello,

 

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!

 

Sincerely

Elijah G.
API Support Engineer
Highlighted
Occasional Contributor

Re: Bad request when trying to addContact()?

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?

Highlighted
Employee

Re: Bad request when trying to addContact()?

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

Highlighted
Occasional Contributor

Re: Bad request when trying to addContact()?

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.

Highlighted
Employee

Re: Bad request when trying to addContact()?

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 webservices@constantcontact.com 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

Highlighted
Occasional Contributor

Re: Bad request when trying to addContact()?

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 :)

Highlighted
Employee

Re: Bad request when trying to addContact()?

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

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