Supplied examples: "Must supply a valid HTTP Basic Authorization heade

I am using the supplied example to test the API with the PHP library:

require_once 'csrest_general.php';

$auth = array('api_key' => 'your API key');
$wrap = new CS_REST_General($auth);

$result = $wrap->get_clients();

However, the response I get is;

   'Code' => 50,
   'Message' => 'Must supply a valid HTTP Basic Authorization header',

I have also tried using the supplied example for adding subscribers, with the same result.

How do I set the Basic Auth header? Given the docs say that Basic Auth simply requires the API key as the username and a blank password, I assumed the library would handle that if I just give it an API key, as the samples do.

Phil Phil, 3 years ago

Hi, i answered this over on Github, but for completion i'll paste my response here too:

You need to ensure that in this line you correctly replace 'your API key' with the actual ApiKey from your account:

$auth = array('api_key' => 'your API key');

If you have, and it's still not working, it's likely that instead of the ApiKey you're using a ListID or ClientID. The ApiKey is obtained by clicking on the "Account Settings" link when you're logged into your account.

If you're still having troubles you'll need to log a support request so we can look at your individual case.

phillichfielddc, 3 years ago


Yep, it's definitely the account key from Account Settings (top bar) > Show API key.

I'll open a support request as you suggest.


Join 150,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free