Problem with subscriberAddWithCustomFields in PHP

Hi All,

I'm trying to make subscriberAddWithCustomFields works with the PHP Sample and I'm having problems for the last 5 hours with it, so it's time to ask for a little help

I have a list with two custom fields, one is Multi-Options (select many) (called 'opcoes'), and the other is a Multi-Options (select one)(called 'mes'), and I can't figure out how I need to code this to make it insert the two fields heres my code:

[code]<?php

require_once('api/CMBase.php');
$api_key = 'APIKEY';
$list_id = 'LISTID';

$cm = new CampaignMonitor($api_key, null, null, $list_id,'soap');

$userEmail = "EMAIL";
$userName = "NAME";
$informations = array('opcoes' => 'Taco el Pancho', 'Todos'), array('mes' => 'mar')

$result0 = $cm->subscriberAddWithCustomFields($userEmail, $userName, $informations);

$result1 = $cm->subscribersGetActive();

print_r($result0); //Array ( [code] => 0 [Message] => Success )

print_r($result1); // It's empty ( how I can Successfully add, and the user don't show up it's weird to me, I've tried without the $informations bit and the result is the same )[/code]
Any Clue ??

And please CM, could you add some simple examples about using the API Samples ?

TIA
Marcelo Wolfgang

Ken Ken, 7 years ago

Hi Marcelo,

You need to use this following line:

$informations = array('opcoes' => array('Taco el Pancho', 'Todos'), 'mes' => 'mar');

This should work now.

The file Subscriber.AddWithCustomFields.php from http://www.campaignmonitor.com/api/kits/#php-sample does have an example of how to format the custom field array.

Feel free to get back to us if you have any other problems or questions.


http://www.campaignmonitor.com
grillo, 7 years ago

Hi Ken,

Thanks for the response, After a couple of more try and error I came up with:

$informations = array("opcoes" =>array ( "taco el pancho","soviet"), "mes" =>array ("mar"));

which is the same thing, actually it was more of a lack of knowledge of php from my part than anything else.

Thanks

Paul Davis, 7 years ago

Hi

I'm having similar problems getting this to work. I've tried the suggestions above but no joy :(

Script is as follows:

<?php
    require_once('CMBase.php');
       
    $api_key = 'my_api_key';
    $client_id = null;
    $campaign_id = null;
    $list_id = 'my_list_id';
    $cm = new CampaignMonitor( $api_key, $client_id, $campaign_id, $list_id, 'soap');
   
    $result = $cm->subscriberAddWithCustomFields($Email, $Name, array('Title' => $Title));
   
    if($result['Code'] == 0)
        echo 'Success';
    else
        echo 'Error : ' . $result['Message'];
   
?>

I have the permissions of both this and the CMBase.php set to 755.

The variables $Email, $Name, and $Title are passed from a form which uses a POST action pointing at this php script.

Can anyone tell me what I'm doing wrong?

Much appreciated!!

grillo, 7 years ago

I couldn't figure out what was wrong, but maybe:

array('Title' => $Title)

should be

array('Title' => '$Title')

HTH

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