Got a 'How do I' question? Join 'Ask a Trainer' Monday to Friday, 11am to 4pm ET for instant help and pro tips!

PHP SDK Compatiblity with PHP 7

_Mystic_Chorale
Campaign Expert
0 Votes

Hi there:

I set up a Constant Contact integration for our website using the PHP SDK adapted from the sample code for the email signup form (https://github.com/constantcontact/php-sdk/blob/development/examples/addOrUpdateContact.php). We recently upgraded our server to PHP 7.2.12 and have been receiving the following error:

 

Fatal error: Cannot use lexical variable $eventName as a parameter name in /nfs/c04/h02/mnt/67435/domains/mysticchorale.org/html/wp-content/themes/mc/constant_contact_library/vendor/guzzlehttp/guzzle/src/Ev... on line 48

 

Is there any way of updating the PHP SDK files to address this error and make the library usable with PHP 7?

 

If the library is not compatible is there an equivalent example you can provide similar to the sample code I linked above for a sign up form that would be compatible with V3 of the API? I did briefly review the V3 documentation and was confused, I don't understand how to duplicate the functionality I was able to set up using the PHP SDK with V2 in V3 of the API.

 

Without going into detail the Constant Contact integration on our site is more complicated than a simple sign up form. The integration is handled as part of a larger member registration process which triggers list updates in a few different circumstances (including being initiated by the purchase of a product in WooCommerce).

 

Hope all of the above makes sense. Please get back to me when you have a chance. I need to have a solution in place for this by Monday December 2nd. Thanks for your help!

-Robert

3 REPLIES 3
Jimmy_D
Employee
0 Votes

Hello @_Mystic_Chorale,

 

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

 

Our primary focus is developing our v3 API which means we are not updating on our SDKs for v2. I am happy to answer any questions you have regarding replicating your integration in the v3 if that is your best option. Feel free to post your questions here, or if the information needs to remain private you can reach us by emailing webservices(at)constantcontact(dot)com.


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

Hi Jimmy:

 

Thanks for getting back to me. Sounds good, I will have a go at setting up our integration with the V3 API. Before I start working on this I have a few follow up questions: one general question concerning interacting with the API and a few questions specific to our integration.

 

For the general question I just wanted to confirm how data is sent and received from the V3 API using PHP. Instead of using a wrapper library (like the PHP SDK used with the V2 API) communicating with the V3 API uses JSON/Curl functions in PHP to send and receive the data. Data is formatted as JSON then sent to the API using Curl functions to the relevant endpoint, and vice-versa where data is received via Curl functions as JSON and decoded in PHP. Is this a correct outline of the general connection process or is there a different method I should be using to send/receive data from the V3 API?

 

For the next set of questions I just wanted to briefly outline how our integration works and confirm that it will be possible to work with our mailing lists through the V3 API in the following scenarios. Without going into too much detail singers register to sing for a season with our choral group, as part of the registration they are added to one or more mailing lists in our Constant Contact account specific to each season. Here are the basic steps involved:

 

  1. Retrieve all mailing lists from our CC account via the API. Get the list ID numbers of the lists associated with the current season by matching the data returned by the API with the lists specified in our local database.
  2. Via the API check to see if a contact already exists in our CC account for the email address provided by the singer who is signing up. If a contact doesn't exist add the signer as a new contact (first name, last name, email address).
  3. Add the singer to the respective mailing lists for the season (from step 1 above).

This process also needs to run in reverse where singers can use a form on our website to drop out of a season. In this case they are removed from the respective season mailing lists, however they are left as a contact in our CC account.

 

A third situation occurs when the user changes their email address in our local database. In this case the singer needs their old email address removed from the respective season lists, and added to the lists under their new email address. Ideally the existing contact would be updated with the new email address in CC (rather than creating a new contact).

 

Three more general questions:

 

  1. We only need to pass first name, last name, and email address when creating new contacts via the API. Are there any other properties that need to be set when creating contacts dynamically via the API ? Just want to make sure there aren't any status issues since the user is not directly interacting with Constant Contact like they would be using a simple sign up form.
  2. In reviewing the documentation I noticed that in the formatting of the JSON object for a contact the mailing list information (which mailing lists the user belongs to) is nested on the second level within another property. Should I be passing these as a nested/multi-dimensional array in PHP when converting to a JSON object for sending to the API?
  3. In reviewing the documentation for the V3 API the basic example involves uploading contacts from a CSV file which is not relevant to our integration which I outlined above. Is there any other sample code I can look at that more closely matches what I outlined for our integration above? In particular I am concerned that our integration is done entirely programmatically with no clicking/interaction by the user, just want to make sure there aren't any issues I could be missing in this regard.

Hope all of the above makes sense, please get back to me when you have a chance. I am hoping to work on this on Friday night, if you have time to get back to me later today or during the day on Friday that would be great. Thanks again for your help!

 

-Robert

Jimmy_D
Employee
0 Votes

Hi @_Mystic_Chorale,

 

The v3 API sends/receives data exactly the same as our v2 API; it is a RESTful API. The data payload is formatted in the JSON format and the endpoints are just http requests. How you choose to write that in your code is completely up to you. Our v2 SDK did use a cURL library to accomplish it's requests.

 

In regards to how your integration currently works with adding contacts and adding them to the contact lists. The v3 works in the same way. The ID format for contacts and lists has changed format, but that will not change how your integration works.

 

General Questions

1. There are no new status or anything. The creation process is the same; there is added functionality if you want to use it such as birthdays and anniversaries.

 

2. The contact list is now considered to be a sub resource which is why it is a separate array. Each sub resource is its own array within the main object. Here is an example of how I would format the JSON.

 

 

{
"email_address": {
"address": "xxxx@example.com",
"permission_to_send": "implicit"
},
"first_name": "xxxx",
"last_name": "xxxx",
"create_source": "Account",
"list_memberships": [
"xxxxx"
]
}

 

 

3. Our documentation should show an example for a single contact creation as well as a bulk import from csv. Here is the link to the single contact creation. https://v3.developer.constantcontact.com/api_guide/contacts_create.html#example-post-create-a-contac...


Regards,
Jimmy D.
Tier II API Support Engineer
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