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.

PHP API CustomFieldNN json error

Highlighted
Solution Provider

PHP API CustomFieldNN json error

I am trying a very simple integration... 

- test to see if a user exists

- if not, create

- if so, update

 

My code almost mirrors example from CC.

 

I keep getting the following error:

[error_key] => json.regex.mismatch.custom_fields
[error_message] => #/custom_fields/1/name: This attribute value must be of the format 'CustomFieldNN'

 

Funny thing is, I'd like to update the CustomFields, but I'm not even there yet... ;)

 

Suggestions?

 

Thanks!

 

Code:

$cc = new ConstantContact(APIKEY);

try {
// see if the sperson already exists in the account
$response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['emailAddress']);

// create it if it does not exist and add category

if (empty($response->results)) {
$contact = new Contact();
$contact->addEmail($_POST['emailAddress']);
$contact->addList('1320236928');
$returnContact = $cc->addContact(ACCESS_TOKEN, $contact);
} else {
// update an existing contact
$contact = $response->results[0];
$contact->first_name = 'Jim';
$contact->addList('1320236928');
$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact);
}
// catch any exceptions thrown during the process and print the errors to screen
} catch (CtctException $ex) {
echo '<span class="label label-important">Error '.$action.'</span>';
echo '<div class="container alert-error"><pre class="failure-pre">';
print_r($ex->getErrors());
echo '</pre></div>';
die();
}

13 REPLIES 13
Highlighted
Solution Provider

Re: PHP API CustomFieldNN json error

Further trouble shooting shows it works creating and updating contacts if they do not have any custom info.  If they do, it barfs with the above mentioned error.  Dumping out the arrays, it doesn't seem like the array structure is changing any.

 

Another interesting point is that it still barfs when I delete a contact with a custom field and then try to readd it...  apparently the system remembers deleted contacts...

 

Any help is appreciated.

 

Thanks.

Highlighted
Moderator

Re: PHP API CustomFieldNN json error

The second part of your question is easier to answer - deleted contacts are kept around for a period of time.  In our old CMS, they are kept around forever and never truly deleted.  In our new CMS, which it sounds like you're on, Contacts can be completely deleted if they aren't Unsubscribed (those we keep around forever to honor their unsubscribe) but they are not deleted immediately in case you made a mistake you can then recover from it. 

 

Regarding the first part of your post, we are working on a bug right now around custom fields with our new CMS system.  Unfortunately, it was both unexpected (as most bugs are) and especially complicated.  We are working hard to fix it but as of now, we don't have a very good workaround.  The problem is that the custom_field->name object is coming back as the label that it is configured as (for example "Favorite dog") instead of the number of the field (for example "CustomField1").  As such, it isn't matching the expected format the API needs to map the field correctly. 

 

We will update once we have a fix for this.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Solution Provider

Re: PHP API CustomFieldNN json error

What is the ETA on resolution and is there a work around?

Highlighted
Moderator

Re: PHP API CustomFieldNN json error

At this point, the only workaround is to not update the custom fields or not send them over.  We don't really have a generic workaround for how to map these fields as there is no obvious way.  I also don't have an ETA as this is a very complex technical problem that we're still evaluating potential solutons for, there is no clear resolution and we don't want to do something that makes the problem worse. 

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Solution Provider

Re: PHP API CustomFieldNN json error

Upon request, CustomFields are in the contact object.  You can add other custom fields using the PHP API, but there is no way to delete them before resubmiting for update.

 

How do you recommend deleting the CustomFields elements of the array/JSON object using the PHP library?

 

Thanks.

Highlighted
Honored Contributor

Re: PHP API CustomFieldNN json error

Hello,

 

I've taken a look at your code and the issue you've run into, and the easiest way around this is to simply remove the custom fields from the contact object. In the case of our PHP wrapper, we build the class to mirror the JSON structure for the API and use PHP's json_encode function to generate the payload.

 

Because of this, you can do the following to ignore any custom fields:

$contact = $response->results[0];
$contact->custom_fields = array();

 

Once you do this, you should be able to avoid the naming issue with the custom fields until we have something more available.

 

If you run into any problems with this, plaese let me know and I'll be happy to help!

 

Sincerely,

Elijah G.

API Support Specialist

Elijah G.
API Support Engineer
Highlighted
New Member

Re: PHP API CustomFieldNN json error

Has this issue been fixed yet? I am getting the same error when I try to add custom fields

Highlighted
Occasional Participant

Re: PHP API CustomFieldNN json error

^... and the answer is....  Yes or No?

 

Can custom fields be added to the json object/array and passed successfully to CC using the php_sdk?

Highlighted
Honored Contributor

Re: PHP API CustomFieldNN json error

Hello,

 

This issue was fixed close to the end of 2013 and has been corrected. You can now use the PHP SDK to manage custom fields for contacts and should not have the problem that is described in this tread.

 

If you do experience any issues, please let us know!

 

Best Regards,

Elijah G.
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