I am using https://developer.companieshouse.gov.uk/api/docs/ to access an API I have my API key, however, i am not sure how to pass that from VBA. So far i tried below
I found it.. i was missing to encode the key
Function EncodeBase64(text As String) As String
Dim arrData() As Byte
arrData = StrConv(text, vbFromUnicode)
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
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
Basic auth requires the username and password to be base 64 encoded together. The AuthKey you need to pass is essentially:
def unencoded_auth = "[username]:[authkey]"
def encoded_auth = *call-to-base64-encode-value*(unencoded_auth)
Then you would replace
"Basic " & AuthKey
with
"Basic " & encoded_auth
I'll reference this post as to how to achieve the base64 encoding.