campaignmonitor / createsend-php

A PHP library for the Campaign Monitor API
http://campaignmonitor.github.io/createsend-php
Other
285 stars 107 forks source link

Error 50: Must supply a valid HTTP Basic Authorization header #15

Closed thomaspuppe closed 11 years ago

thomaspuppe commented 11 years ago

When I want to add Subscribers toi the CampaignMonitor API using this wrapper, I get the following reponse:

Result of POST /api/v3/subscribers/{list id}.{format} 
Failed with code 401 

object(stdClass)#5 (2) {
   ["Code"]=>
  int(50)
  ["Message"]=>
  string(51) "Must supply a valid HTTP Basic Authorization header"
}

https://www.campaignmonitor.com/forums/topic/5711/must-supply-a-valid-http-basic-authorization-header-classic-asp/ says that the Auth Header must be base46 encoded. But this is already the case in your CS_REST_SocketTransport class (/class/transport.php).

thomaspuppe commented 11 years ago

This is funny ... I compared the code to an old version of the Wrapper (CS_REST_Wrapper v2.4.0) that I use in another project and that also talks to the CampaignMonitor API v3. This version does not base64_encode the credentials (apikey:nopass). So I changed

'credentials' => base64_encode($api_key.':nopass'),

to

'credentials' => $api_key.':nopass',

in function CS_REST_Wrapper_Base (createsend-php-master\class\base_classes.php line 147).

And now it works. Can anyone explain this to me? Has anyone else discovered problems with atuhentication? Or is anyone here who uses the wrapper successfully without this modification?

thomaspuppe commented 11 years ago

I just have found out that it was my error, and found out what the reason was.

  1. I got the "Must supply a valid HTTP Basic Authorization header" error message and googled it.
  2. I found the base64_encode() hint and added it.
  3. Later I also changed the API credentials (used the Account API key instead the Client API key.
  4. Then I removed the base64_encode function (that I included by myself previously).
  5. Now it works.

If I just did 3 instead of all the other stuff, it would have been fine.

Sorry for the confusion.