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, 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',
//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, 4 years ago

Thanks.

Obviously need to get my eyes checked!

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