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, 9 years ago

I'm using NUSOAP0.7.3

Toby Brain, 9 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.

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free