Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supplied examples: "Must supply a valid HTTP Basic Authorization header" #33

Closed
philipjohn opened this issue Apr 29, 2014 · 4 comments
Closed

Comments

@philipjohn
Copy link

I am using the supplied example to test the API:

require_once 'csrest_general.php';

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

$result = $wrap->get_clients();
var_dump($result->response);

However, the response I get is;

array(
   '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.

@itgoeslikethis
Copy link
Contributor

Hi @philipjohn,

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.

@nijeshhirpara
Copy link

nijeshhirpara commented May 16, 2016

Hi @itgoeslikethis @philipjohn,

I am having similar issue.
here is my code,

require_once '../../csrest_clients.php';

$auth = array('api_key' => 'Your API Key');
$wrap = new CS_REST_Clients($auth);

$result = $wrap->create(array(
    'CompanyName' => 'Test',
    'Country' => 'Australia',
    'Timezone' => '(GMT+09:30) Adelaide'
));

echo "Result of POST /api/v3.1/clients\n<br />";
if($result->was_successful()) {
    echo "Created with ID\n<br />".$result->response;
} else {
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}

Response which I am getting,

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

I have checked API key as well. It's correct. Please let me know the resolution if you had it.

@asadighi
Copy link
Contributor

Is this exact excerpt from your code?

$auth = array('api_key' => 'Your API Key');

@itgoeslikethis
Copy link
Contributor

Hi @nijeshhirpara ,

Unfortunately there could be a number of reasons that you're getting that response, but it in some way it indicates something wrong with the Authorization header that's coming through. You've said that you think the API key is correct, so here's a few options:

  • There is a bit of trailing or leading whitespace in the APIKey string (eg " abdcef12")
  • A proxy or firewall is stripping the Authorization header from outgoing traffic from your server
  • What you've put in as the APIKey is some other string (perhaps a Client-level APIKey - for creating Clients you need to have an Account-level key, or maybe just a ClientID)

Do you think it could be any of those?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants