从Excel VBA向Freshdesk API v2验证以下PUT请求时遇到问题。我是这个(VBA)的新手,但我想我太关闭了,谁能告诉我这段代码有什么问题以及为什么我收到一条调试消息
{“代码”:“ invalid_credentials”,“消息”:“您必须登录才能执行此操作。”}
var checkbox = document.querySelector("#check");
checkbox.addEventListener( 'change', function() {
var concession = document.getElementById("hidden");
if(this.checked) {
concession.style.display='block';
} else {
concession.style.display='none';
}
});
答案 0 :(得分:0)
我已经破解了。该API令牌是作为字符串提交的,但需要将其编码为base64。
我使用了发现的以下功能:
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
并更改了行
objHTTP.setRequestHeader "Authorization", "Bearer " & token
到
objHTTP.setRequestHeader "Authorization", "Bearer " & EncodeBase64(token)