Basic Authentication

MSXML worked fine in V2 of the API but I can't get it to work in V3, I keep getting the following response:
<?xml version="1.0" encoding="utf-8"?><Result><Code>50</Code><Message>Must supply a valid HTTP Basic Authorization header</Message></Result>

Can anyone let me know why the following simple vba code does not work:


Private Sub Test_API()

    Dim XMLHTTP As MSXML2.ServerXMLHTTP60

    Set XMLHTTP = New MSXML2.ServerXMLHTTP60
    XMLHTTP.setProxy 2, "http://ptcprox1:8080"
   
    XMLHTTP.Open "GET", "http://api.createsend.com/api/v3/clients/{clientID}.json", False, "", ""
    XMLHTTP.setRequestHeader "Authorization", "Basic " & EncodeBase64("{APIKey}:")
    XMLHTTP.send
           
    MsgBox XMLHTTP.responseText

End Sub

Function EncodeBase64(text As String) As String
 
  Dim arrData() As Byte
  arrData = StrConv(text, vbFromUnicode)

  Dim objXML
  Dim objNode

  Set objXML = New MSXML2.DOMDocument
  Set objNode = objXML.createElement("b64")

  objNode.DataType = "bin.base64"
  objNode.nodeTypedValue = arrData
  EncodeBase64 = objNode.text

  Set objNode = Nothing
  Set objXML = Nothing
 
End Function

orenpv, 6 years ago

I worked it out.

For anyone interested you need to add a dummy password i.e.

XMLHTTP.setRequestHeader "Authorization", "Basic " & EncodeBase64("{APIKey}:{dummypassword}")

jamesd jamesd, 6 years ago

Glad you worked it out. This is actually quite clearly explained in the authentication documentation.

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