"subscriberAdd" Works Easy, "subscriberAddWithCustomFields" Does Not?

Hello Everyone,
I've started playing with the API today, and I'm able to follow the php examples to add subscribers via my own form, using php to send the request once the form is submitted. I've been using the subcriberAdd() function without any problems, but I cannot get subscriberAddWithCustomFields() to work at all yet.

1.) I've got this to work fine:
$result = $cm->subscriberAdd($email, $your_name);

2.) But the following doesn't insert any information into the createsend.com database:
$result = $cm->subscriberAddWithCustomFields($email,$your_name, array("Gender" => "Male"));

The result code says that the query was successful, and I've tried different variations on the custom field. Inserting "Gender" or looking at the field name generated by the auto form builder to insert "cm-f-nodk" both do nothing. Not even the name and email are inserted.

I've even tried running subscriberAdd() followed immediately by subscriberAddAndResubscribeWithCustomFields() but the custom field isn't updated. I've copy and pasted all of the examples, and I've created multiple Lists both populated with the custom fields beforehand then without the custom fields created but I haven't gotten anything to work with custom fields. Turning on the double opt-in option doesn't affect the outcome either.

And here's the debugging info when trying
$result = $cm->subscriberAddWithCustomFields($email,$your_name, array("Gender" => "Male"));
CampaignMonitor Object (
[url]=> http://api.createsend.com/api/api.asmx
[soapAction] => http://api.createsend.com/api/
[api] => c9eabb523278febbf9db432ba924e33f
[campaign_id] =>
[client_id] => XXXXXXXXXXXXX
[method] => soap
[curl] => 1
[curlExists] => 1
[debug_level] => 1
[debug_request] =>   c9eabb523278febbf9db432ba924e33f  6311554db0317ee2b4de2f351123ffe8  asgasd@asdobe.com  dfagd    Gender  Male     
[debug_response] =>
[debug_url] => http://api.createsend.com/api/api.asmx

[debug_info] => Array (
   [url]=> http://api.createsend.com/api/api.asmx
   [content_type] =>
   [http_code] => 400
   [header_size] => 206
   [request_size] => 889
   [filetime] => -1
   [ssl_verify_result] => 0
   [redirect_count] => 0
   [total_time] => 0.157278
   [namelookup_time] => 0.036093
   [connect_time] => 0.072016
   [pretransfer_time] => 0.072034
   [size_upload] => 647
   [size_download] => 0
   [speed_download] => 0
   [speed_upload] => 4113
   [download_content_length] => -1
   [upload_content_length] => -1
   [starttransfer_time] => 0.157123
   [redirect_time] => 0
   [headers_sent] => Array ( [0] => User-Agent: CMBase URL Handler 1.5 [1] => Content-Type: text/xml; charset=utf-8 [2] => SOAPAction: "http://api.createsend.com/api/Subscriber.AddWithCustomFields" ) )
   [show_response_headers] => 0 )
I've searched the forums and I've been working on this for a few hours, so I'd very much appreciate any hints and tips anyone might have to help me get this working.

Thank you very much!

deanbeasley, 8 years ago

I have exactly the same probelm, did you reseolve this? Even support havent got a clue, where do we go from here?

jerrygarciuh, 8 years ago

I have a thread on this from last month as well.  Support referred me to the author who did not answer emails even when offered money.

If you look at the SOAP envelope data you'll see several fields where what should be the closing tag lacks the slash. 

If you look at the http_code field in the debug info it shows a 400 (Bad Request) which should mean in this case the server said the XML was malformed.

Testing this idea today.


jerrygarciuh, 8 years ago

Got it solved.  Will post patch in a few.

jerrygarciuh, 8 years ago

OK, in cmBase.php you will want to replace lines 821 - 853, the array2xml() function.

All I did was add the trailing slashes.

I cannot believe this was being distributed as if it worked.  It could never have worked as it was.  It must have been untested.

function array2xml( $arr, $indent = '', $escape = true )
    $buff = '';
    foreach ( $arr as $k => $v )
        if ( !is_array( $v ) )
            $buff .= "$indent<$k>" . ($escape ? utf8_encode( $v ) : $v ) . '</' . "$k>\n";
            Encountered a list. The primary difference between the two branches is that
            in the 'if' branch, a $k element is generated for each item in $v, whereas
            in the 'else' branch, a single $k element encapsulates $v.
            if ( isset( $v[0] ) )
                foreach ( $v as $_k => $_v )
                    if ( is_array( $_v ) )
                         $buff .= "$indent<$k>\n" . array2xml( $_v, $indent . "\t", $escape ) . "$indent" . '</' . "$k>\n";
                        $buff .= "$indent<$k>" . ($escape ? utf8_encode( $_v ) : $_v ) . '</' . "$k>\n";
                $buff .= "$indent<$k>\n" . array2xml( $v, $indent . "\t", $escape ) . "$indent" . '</' . "$k>\n";
    return $buff;

jamesd jamesd, 8 years ago

Please see my reply here: http://www.campaignmonitor.com/forums/viewtopic.php?id=2492

Please respond there with your feedback there/here. Your line number references would indicate that you are not using the latest version of the wrapper.

It's always best to check for the latest version in case there have been fixes made in the meantime.

jerrygarciuh, 8 years ago

Please see my reply to James here:  http://www.campaignmonitor.com/forums/viewtopic.php?id=2492

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