Invalid email address - php API


I'm trying to test the API by adding a subscriber.

I've copied the example from the API code on github and modified it to my requirements:

require_once 'csrest_subscribers.php';

$wrap = new CS_REST_Subscribers('XXX', 'XXX');

$result = $wrap->add(array(
    'EmailAddress' => 'Subscriber email',
    'Name' => 'Subscriber name',
    'CustomFields' => array(
            'Key' => 'name',
            'Value' => 'Test'
            'Key' => 'email',
            'Value' => ''
    'Resubscribe' => true

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>';

But it gives me the following error message:

Result of POST /api/v3/subscribers/{list id}.{format}
Failed with code 400
object(stdClass)#5 (2) {
  string(37) "Please provide a valid email address."

What am I doing wrong?

Any advice appreciated.


Phil Phil, 4 years ago

Hi Dan,

The email address you've submitted is literally "Subscriber email". From your code:

$result = $wrap->add(array(
    'EmailAddress' => 'Subscriber email',
    'Name' => 'Subscriber name',

Name and email aren't custom fields - they're fundamental attributes of a Subscriber.

Try this:

$result = $wrap->add(array(
    'EmailAddress' => '',
    'Name' => 'Test',
    'Resubscribe' => true
danrp, 4 years ago


Obviously need to get my eyes checked!

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free