Add Subscriber stops working (v3)

I'm working on a plugin to add people who purchase from our cart to our list. This was working just fine in my testing, but now I keep getting this error

Failed with code 0 

I've restored my file back to versions that I thought were working before, but still no luck. Here's my API portion of the plugin. I've removed the ID's.

require_once 'cm/csrest_subscribers.php';
$wrap = new CS_REST_Subscribers('xxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxx');
$result = $wrap->add(array(
    'EmailAddress' => $purchase_log_data_email,
    'Name' => $purchase_log_data_firstname .' '. $purchase_log_data_lastname,
    'CustomFields' => array(
            'Key' => 'Total',
            'Value' => $purchase_log['totalprice']
            'Key' => 'Purchase Date',
            'Value' => $purchase_log['date_purchased']
            'Key' => 'Product',
            'Value' => $purchase_log_data_item['name']

echo "Result of POST /api/v3/subscribers/{list id}.{format}\n<br />";
if($result->was_successful()) {
    echo "Subscribed with code ".$result->http_status_code;
} else {
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
    echo '</pre>';

Any ideas? What does "Failed with code 0 bool(false)" mean exactly? Any help would be appreciated, thanks.

tobyb tobyb, 5 years ago

Hey epschmidt, welcome to the forums.

When the call returns false, it usually means that the wrapper was not able to access the api. You should be able to get more info about why the api is inaccessible by printing the logging information made with each request.

To do this change your constructor call to

$wrap = new CS_REST_Subscribers('xxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxx', 'https', CS_REST_LOG_VERBOSE);

Usually it will be an environmental issue but if your still having trouble reply with the logging data and we can have a look into it.

epschmidt, 5 years ago

Thanks for your response. I tried it again this morning, both with your changes and without, and it worked just fine. Is there a limit to the number of times you can connect to the API, or connect to the same subscriber in one day? I was testing different custom fields yesterday and it seemed to just stop working all of the sudden. And now this morning it works fine, without me changing anything.

epschmidt, 5 years ago

So I began working on an admin options page in WordPress for my plugin and now adding subscribers through the API is failing again. I've restored the original file that did work this morning and it is still failing. Here is the log...

12:59:59 - CS_REST_Subscribers: Creating wrapper for
12:59:59 - CS_REST_Subscribers: Using cURL for transport
12:59:59 - CS_REST_Subscribers: Getting serialiser
12:59:59 - CS_REST_Subscribers: Using native json serialising
12:59:59 - CS_REST_Subscribers: Making POST call to:
13:00:00 - CS_REST_CurlTransport: API Call Info for POST 0 bytes uploaded. 0 bytes downloaded Total time (seconds): 0
13:00:00 - CS_REST_Subscribers: Call result:
array (
  'code' => 0,
  'response' => false,

Result of POST /api/v3/subscribers/{list id}.{format} 
Failed with code 0 

Once again I've x'd out our list ID. From what I can tell, the log is the same as the successful one i received this morning.

CS_REST_Subscribers: Creating wrapper for
10:10:13 - CS_REST_Subscribers: Using cURL for transport
10:10:13 - CS_REST_Subscribers: Getting serialiser
10:10:13 - CS_REST_Subscribers: Using native json serialising
10:10:13 - CS_REST_Subscribers: Making POST call to:
10:10:14 - CS_REST_CurlTransport: API Call Info for POST 219 bytes uploaded. 29 bytes downloaded Total time (seconds): 0.503024
10:10:14 - CS_REST_Subscribers: Call result:
array (
  'code' => 201,
  'response' => '""',

Result of POST /api/v3/subscribers/{list id}.{format} 
Subscribed with code 201
tobyb tobyb, 5 years ago

It definitely looks like the wrapper can't access our API. Unfortunately it doesn't look like we're logging the reason that curl is failing to access the API. I've just pushed some changes to the GitHub repo which will do just that, which will hopefully help you track down the problem.

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