Invalid email address - php API

Hi,

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(
        array(
            'Key' => 'name',
            'Value' => 'Test'
        ),
        array(
            'Key' => 'email',
            'Value' => 'my@email.com'
        ),
    ),
    '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>";
    var_dump($result->response);
    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) {
  ["Code"]=>
  int(1)
  ["Message"]=>
  string(37) "Please provide a valid email address."
}

What am I doing wrong?

Any advice appreciated.

Thanks

Phil Phil, 5 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',
//etc

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

Try this:

$result = $wrap->add(array(
    'EmailAddress' => 'my@email.com',
    'Name' => 'Test',
    'Resubscribe' => true
));
danrp, 5 years ago

Thanks.

Obviously need to get my eyes checked!

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