constantcontact / php-sdk

Constant Contact PHP SDK for v2 API
Other
105 stars 126 forks source link

Can't add named custom field #29

Open jahvi opened 11 years ago

jahvi commented 11 years ago

I have a custom field in my account called "comment" however when I try to create a new contact like this:

$contact = new Contact();
$contact->addEmail($email);
$contact->addList($list);
$contact->first_name = $first_name;
$contact->last_name  = $last_name;
$contact->custom_fields = array(array('name' => 'comment', 'value' => $comment));

$cc->addContact(CC_TOKEN, $contact);

I get the following error:

array (size=1)
  0 => 
    array (size=2)
      'error_key' => string 'json.regex.mismatch.custom_fields' (length=33)
      'error_message' => string '#/custom_fields/0/name: This attribute value must be of the format 'CustomFieldNN'' (length=82)

It looks like the API expects the custom field name to be "CustomFieldNN" and it looks like my "comment" field is getting assigned as "CustomField0" but even if I change my code to:

$contact->custom_fields = array(array('name' => 'comment', 'value' => $comment));

I still get the same error, is it not possible to add/update named custom fields?

richm541 commented 11 years ago

Hi Javier,

I updated the API docs for Contacts yesterday regarding CustomFields here: http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST

Sounds like your account is using the new contact management system which supports custom fields with fewer or no restrictions on naming. Currently the API only supports the CustomField1 -> 15 naming convention, and ignores custom fields that don't follow that convention. I'll check for other open issues that you might be running into, if any. Rich

jahvi commented 11 years ago

I see, that's a bummer

On Sat, Oct 26, 2013 at 10:33 AM, richm541 notifications@github.com wrote:

Hi Javier,

I updated the API docs for Contacts yesterday regarding CustomFields here:

http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST

Sounds like your account is using the new contact management system which supports custom fields with fewer or no restrictions on naming. Currently the API only supports the CustomField1 -> 15 naming convention, and ignores custom fields that don't follow that convention. I'll check for other open issues that you might be running into, if any. Rich

— Reply to this email directly or view it on GitHubhttps://github.com/constantcontact/php-sdk/issues/29#issuecomment-27148046 .

Ing. Javier Villanueva

jasonyarrington commented 10 years ago

Any update on this in the API?

richm541 commented 10 years ago

Hi Jason,

We are starting work on making the API user experience re:Contacts to be on par with the GUI experience now that all accounts have been migrated to the new contact management system. This will be ongoing work, with iterative updates over 6 -12 months, with iniitial changes expected in Q4 this year. I am being conservative and open so as not to set inappropriate expectations.

Rich

zanematthew commented 9 years ago

Would it be possible to pull in a list of said custom fields via the API?

deefour commented 9 years ago

@richm541 is there any update on the ability to use $label and $name with a custom field, without the CustomField### naming requirement?

I've never used the GUI or API for ConstantContact before, but see nothing in the custom field or contact panels in the GUI to set a "label" and "name" for the fields separately. Attempting to set a label via the API fails (null response from the ContactService). The same goes when setting the field names to anything but CustomField###.

richm541 commented 9 years ago

customnamedfield @deefour The description of the custom_field property can be found here: http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST#structure

Only custom fields using the prescribed customfieldn format are available via API at this time.

  1. label is read-only property in the API.
  2. Adding a custom field with any name to a contact in GUI as follows: a.Select Contacts, (a list of contacts displays) b. Click on a contact from the list. c. In the Additional contact fields section click Add. d. Find the Add New in the list. Leave the default Text Field type selected. e. Enter the name of the field you would like to add (any name you want). Click Add.

That becomes a new custom field, but it cannot be viewed in the API because the name does not use customfieldn naming format.

richm541 commented 9 years ago

@zanematthew - You cannot grab a list of just the custom fields, you can only view custom fields as related to a contact object.

zanematthew commented 9 years ago

@richm541 glad to know.

zagarskas commented 4 years ago

Its been years now... is this still a problem? it is for me... still stuck using "CustomField1" and "CustomField2" instead of super important sane human words like "Signup Source" and "Industry Interest"

zanematthew commented 4 years ago

Its been years now Seemingly so. Maybe they've OOB?

Anyway, you can make your code more readable by introducing an interface or maybe a DTO, or maybe just simple constants, pun intended ;) into your object/functions/code/whatever.

<?php
namespace ConstantContactFixerCrapper;
Class Constants {
    const SIGNUP_SOURCE = 'CustomField1';
    const INDUSTRY_INTEREST = 'CustomField2';
}

cheers ☕