How do you format Customfields in PHP?

Im using NuSOAP in PHP to add New Subscriber using the 'AddSubscriber' API method.
However I also need to upload demographics to my CM account via the API CustomFields.
But there's no php sample on how to add CustomFields.So based on the basic sample provided on the CM API page I added:

        $params = array('ApiKey' => $apikey,
                    'ListID' => $list_id,
                    'Email' => $member['email'],
                    'Name' => $member['username'],
                    'CustomFields'=>array(
                    array(
                        'Key' =>'userid',
                        'Value' => $member['userid'],
                    ),
                    array(
                        'Key' => 'gender',
                        'Value' => $member['field9'],
                    ),
                    array(
                        'Key' =>'age_range',
                        'Value' => $this->getAgeRange($member['birthday']),
                    ),
                    array(
                        'Key' =>'education',
                        'Value' => $member['field6'],
                    ),
                    array(
                        'Key' =>'occupation',
                        'Value' => $member['field15'],
                    ),
                    array(
                        'Key' =>'industry',
                        'Value' => $member['field5'],
                    ),
                    array(
                        'Key' =>'income',
                        'Value' => $member['field7'],
                    ),
                ),
             );

What Am I doing wrong?
Cheers!

hwz, 8 years ago

I'm using NUSOAP0.7.3

Toby Brain, 8 years ago

The following code should work:

$customFields = array('SubscriberCustomField => array());

$customFields['SubscriberCustomField'][] = array('Key' => '[userid]', 'Value' => $member['userid']);

...

$params = array('ApiKey' => $apikey,
                           'ListID' => $list_id,
                           'Email' => $member['email'],
                           'Name' => $member['username'],
                           'CustomFields' => $customFields);

Hope that helps, if not could you send through the full php script.

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098