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()


    Set XMLHTTP = New MSXML2.ServerXMLHTTP60
    XMLHTTP.setProxy 2, "http://ptcprox1:8080"
    XMLHTTP.Open "GET", "{clientID}.json", False, "", ""
    XMLHTTP.setRequestHeader "Authorization", "Basic " & EncodeBase64("{APIKey}:")
    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.

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free