MS Access VBA MSXML2.ServerXMLHTTP Response Unreadable
Hi,
I have the API working in PHP, but I now need to add functionality to an Access Database.
I have spent the last day searching and have found no solution, I am hoping someone here is able to assist.
I can Refresh the Token without a problem, however when I try to retrieve data the response is rubbish text.
Any errors are returned as JSON, eg when the token has expired I see the reply as I should.
{
"Errors": [
{
"Name": "OAuthTokenIsInvalid",
"Message": "The supplied OAuth token (Bearer) is not valid",
"AdditionalDetails": "Header",
"ErrorCode": 31001,
"Severity": "Error",
"LearnMore": null
}
],
"Information": "Warning, error messages have not been finalised in this release and may change"
}
Say I try to get the File List using the code below:
-------------------------------------------------------------------------------------------------------------------------------
If objXMLRequest Is Nothing Then Set objXMLRequest = New MSXML2.ServerXMLHTTP
With objXMLRequest
.Open "GET", "https://api.myob.com/accountright", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "x-myobapi-key", "Removed Code"
.setRequestHeader "x-myobapi-version", "v2"
.setRequestHeader "Accept-Encoding", "gzip,deflate"
.setRequestHeader "Authorization", "Bearer AAE.... (Removed)"
.Send
If .Status <> 200 Then
'// Error getting OAuth2 token
Err.Raise vbObjectError + .Status, _
Description:="Failed to retrieve OAuth2 Token - " & .Status & ": " & .responseText
End If
'// Get the credentials from the response
strToken = .responseText
End With
Debug.Print strToken
------------------------------------------------------------------------------------------------------------------------------------------------------
The above code (with the correct codes) returns the response:
? ?`I?%&/m?J?t??`$?@????G#)?*??Ve]f@????????N'?\fdl??!????~|?"???~t6?t?O??Ov?????:??G#}?????YV??"K? ....Shortened.
if I use .responseBody instead of .responseText i get:
? ???????????????????????????????????????????????????????????????????????????????????....Shortened.
Any help with this would be greatly appreciated.
For anyone who may have this issue in the future, after more searching I have found a solution.
In VBA the ResponseText is giving the compressed information.
When I remove the line:
.setRequestHeader "Accept-Encoding", "gzip, deflate"
The response is then displayed correctly.