Problem with sending multiple custom fields

Hi Guys,

Just trying to use the API to add a subscriber with 2 custom fields but its only passing one.  A print_r shows both sets of data in the array. 

heres the code:

        class SubscriberCustomField
         public $Key;
         public $Value;
    $url = '';
    $wsdl = '';
    $operation = 'Subscriber.AddWithCustomFields';
    $params = array('ApiKey' => 'xxx', 'ListID' => 'xxx', 'Email' => $email, 'Name' => $name);
    $title = new SubscriberCustomField();
    $title->Key = '[Mobile]';
    $title->Value = $mobile;
    // Add the title field to an array
    $customfields = array(new soapval('SubscriberCustomField', 'SubscriberCustomField', $title, false ,''));
    $title2 = new SubscriberCustomField();
    $title2->Key = '[Favourite]';
    $title2->Value = $favourite;
    // Add the title2 field to an array
    $customfields[] = array(new soapval('SubscriberCustomField', 'SubscriberCustomField', $title2, false ,''));
    $params['CustomFields'] = $customfields;
    $headers = array('Content-Type' => 'text/xml; charset=utf-8');
    $namespace = '';
    $soapAction = '';

    $client = new soapclient($url, $wsdl);
    $result = $client->call( $operation, $params, $namespace, $soapAction , '', '', 'rpc', 'literal');    
    unset( $client );

Basically its only adding the 2nd item.  Any ideas?

Ken Ken, 8 years ago


Firstly, I'm unfamiliar with the language you're using (I suppose that gives it away that I don't know how to program in that language). But it seems to me that you're overwriting $customfields with the 2nd custom field, rather than adding to it. Does that sound right? that would certainly explain why you're only getting the 2nd item.

Maybe someone else knows how to add to the array. Normally, I would declare an array of size 2 and assign the 2 custom fields to each bit. Could you try that?

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