Hello,

Not sure if anyone on here has worked with Constant Contact but I thought I would give it a shot. I am trying to upload contacts to their system via their API. All is fine until I try using what they call "Custom Fields". I can upload their predefined fields: First Name, Last Name, Email, etc... but I want to add a "Custom Field" to add our Customer Number.

Currently for testing I've created 1 custom fields labeled: 'custom_field_1' per their documentation.

This is the error I get when trying to add contacts with Custom Fields:

Array
(
[0] => stdClass Object
(
[error_key] => json.type.invalid
[error_message] => #/custom_fields: Value is of a disallowed type. Allowed types are: Array, Null.
)

)

Here is what I've tried:

        // $custFPre =  ['name' => 'custom_field_1', 'value' => '12345'];
        // $custF = json_encode($custFPre);

        $custF = '"custom_fields": [
                    {
                        "name": "custom_field_1",
                        "value": "343465"
                    }
                ]';

        $contact = new Contact();
        $contact->addEmail($_POST['email']);
        $contact->addList('1285823438');
        $contact->addList('1597339570');
        $contact->addList('1717557123');
        $contact->first_name = $_POST['first_name'];
        $contact->last_name = $_POST['last_name'];
        $contact->custom_fields = $custF;

You'll see I tried 2 different ways of adding the custom field with JSON.

Here is their guide:
https://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST#structure

I appreciate any thought/suggestions or if anyone else has run into this same issue.

    Scratch that request. If you're using their SDK you do NOT need to json_encode(). You do however need to create a new object for CustomField(). Which I have not seen in any of their documentation. You also need to follow the naming convention of custom_field_1-15.

    In case anyone else runs into this:
    $contact = new Contact();
    $customField = new CustomField();

            $contact->addEmail($_POST['email']);
            $contact->addList('1285823438');
            $contact->addList('1597339570');
            $contact->addList('1717557123');
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];
            $customField->name = 'custom_field_2';
            $customField->value = '40250';
            $contact->addCustomField($customField);
      Write a Reply...