Constant Contact wants to help you succeed! We’re celebrating our professional service programs on the Constant Contact Community this month and you have a chance to try one of the services for free! Learn more.
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.
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!
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.
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!
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!
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 email@example.com and I'll be happy to take a look for you.
Tier II API Support Engineer