Uncaught Exception Bad Request with PHP SDK

_Mystic_Chorale
Campaign Expert
0 Votes

I am having an issue with the PHP SDK I have been unable to resolve. Without going into detail our site is a Word Press site which allows members to register with the site (creating a Word Press user with a custom role). When members register I am using the PHP SDK to add them to the selected mailing list.

 

I set up a function in my functions file (functions.php) to process the constant contact integration. This function is called mc_update_constant_contact which takes 6 arguments: action (whether member is being added or dropped, first name, last name, email, season id (id of the season they are registering for), and new member (boolean whether the member is a new member). When setting up and testing the function I was able to successfully run it by calling the function directly from a page template. Everything worked correctly and the Constant Contact lists were updated accordingly.

 

However when attempting to run the function as part of the registration form the Constant Contact integration fails. Without getting into detail the registration form uses the Theme My Login and I integrated my Constant Contact function into the function which processes the submission when the registration form is submitted. The registration form runs successfully and the member is added, however the mailing list integration fails.

 

Here is the PHP error message I receive on failure:

 

Uncaught exception 'Ctct\Exceptions\CtctException' with message 'Bad Request' in /Users/trebor/Documents/Sites/wordpress/mc/wp-content/themes/mc/constant_contact_library/vendor/constantcontact/constantcontact/src/Ctct/Services/BaseService.php:78 Stack trace: #0 /Users/trebor/Documents/Sites/wordpress/mc/wp-content/themes/mc/constant_contact_library/vendor/constantcontact/constantcontact/src/Ctct/Services/ContactService.php(203): Ctct\Services\BaseService->convertException(Object(GuzzleHttp\Exception\ClientException)) #1 /Users/trebor/Documents/Sites/wordpress/mc/wp-content/themes/mc/functions.php(1897): Ctct\Services\ContactService->updateContact('ddd578d4-f03e-4...', Object(Ctct\Components\Contacts\Contact)) #2 /Users/trebor/Documents/Sites/wordpress/mc/wp-content/themes/mc/functions.php(1465): mc_update_constant_contact('add', 'Robert', 'Tokey', 'robert.tobey@co...', '2165', true) #3 /Users/trebor/Documents/Sites/wordpress/mc/wp-content/themes/mc/functions.php(1237): mc_create_season_registration('Robert', in /Users/trebor/Documents/Sites/wordpress/mc/wp-content/themes/mc/constant_contact_library/vendor/constantcontact/constantcontact/src/Ctct/Services/BaseService.php on line 78

 

Any ideas on what could be going wrong? I am thinking there is likely an error with where I am placing the require statements for the auto loader script and the use statements for the associated classes. Completely stumped and this is driving me nuts. I can provide more details if needed, hope the above makes sense.

 

 

6 REPLIES 6
_Mystic_Chorale
Campaign Expert
0 Votes

Some additional information to clarify the wordy explanation I gave of the issue above. The function I set up to integrate with Constant Contact through the API is being called from two actions: the user_register action and the profile update action. Where do I place the code for the autoloaders (require_once) and the use statements for the classes so that they will be available when one of the two actions is triggered?

 

Hope that makes more sense!

Jimmy_D
Employee
0 Votes

Hi @_Mystic_Chorale,

 

Thank you for reaching out to Constant Contact's API Support.

 

Going over the information you posted I do agree that the issue is with placing the autoloader and use statements. Our resident PHP expert is out of the office right now; let me do a bit of research to see if I can find a solution for you.


Regards,
Jimmy D.
Tier II API Support Engineer
_Mystic_Chorale
Campaign Expert
0 Votes

Hi Jimmy:

 

Thank you very much for your reply and for looking into my question. When your PHP expert is back in the office please have them post here about the proper placing of the autoloader and use statements. I will also spend some more time troubleshooting this issue and will post here if I am able to come up with a good solution.

 

Thanks again for your help, much appreciated!

_Mystic_Chorale
Campaign Expert
0 Votes

Hello:

I wanted to follow up again on this issue, sorry I have not had a chance to respond again to this earlier. I'm am still having the same issue. I can successfully run the function I set up when calling it directly from a page in Word Press, however when I attempt to call the function when the registration form is submitted in Word Press I get the Bad Request error.

 

Any ideas on how to resolve this? I'm stumped at this point.

 

Thanks again for your help and please get back to me when you have a chance!

David_B.
Employee
0 Votes

Hello,

I do not think this issue is due to your placement of the autoloader/use statements. If that was incorrect, the error you would see would be a Fatal error: Call to undefined function as it tried to use the functions from our SDK. Also, you are getting back a CtctException which tells me that the SDK is installed.

The error you are getting is "Bad Request" which means that there is likely something in the payload that is either unexpected, or malformed. I'd like to see a snippet of the code you are using to make your calls to Constant Contact, and if possible, a sample of all of the parameters you are passing through your function. For privacy, please send this via email to webservices@constantcontact.com and I'll be happy to take a look for you.

Regards,
David B.
Tier II API Support Engineer

user798673
Rookie
0 Votes

Following code for add contenct in the list is not working

$contact = new Contact();
$contact->id = "12345678";
$contact->first_name = "javed";
$contact->last_name = "khan";
$contact->addEmail("javed.khan@example.com");
$contact->addList('099896ba-0ce6-11eb-81d5-**********');
$ctct = new ConstantContact('n4chre33sujpn5ef3*******');
$contacts = $ctct->contactService->addContact('9d2541bf-b864-46e9-990a-***********', $contact, array());
var_dump($contacts);

the following error what gets when executing the above code 

 

An uncaught Exception was encountered

Type: Ctct\Exceptions\CtctException

Message: Bad Request

Filename: C:\xampp\htdocs\vgt-api\application\third_party\vendor-constantcontact\constantcontact\constantcontact\src\Ctct\Services\BaseService.php

Line Number: 78

Backtrace:

File: C:\xampp\htdocs\vgt-api\application\third_party\vendor-constantcontact\constantcontact\constantcontact\src\Ctct\Services\ContactService.php
Line: 144
Function: convertException

File: C:\xampp\htdocs\vgt-api\application\controllers\JConstantcontact.php
Line: 81
Function: addContact

File: C:\xampp\htdocs\vgt-api\index.php
Line: 286
Function: require_once

Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up