Partner Zone

MS Access VBA MSXML2.ServerXMLHTTP Response Unreadable

3 REPLIES 3
AnthRamDF
3 Posts
User

3Posts

0Kudos

1Solutions

Accepted Solution Solved

Re: MS Access VBA MSXML2.ServerXMLHTTP Response Unreadable

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.

 

AnthRamDF
3 Posts
User

3Posts

0Kudos

1Solutions

Re: MS Access VBA MSXML2.ServerXMLHTTP Response Unreadable

Hi @Hannah_B ,

 

Thank you for your reply.

 

The OAuthTokenIsInvalid is not the problem I am having. I put that in to illustrate I am receiving clear messages when an error is thrown.

 

My issue is when I try to retreive data eg, company list , with the correct token, I receive garbage returned eg:

?  ?`I?%&/m?J?t??`$?@????G#)?*??Ve]f@????????N'?\fdl??!????~|?"???~t6?t?O??Ov?????:??G#}?????YV??"K? ....Shortened.

 

 

 

Hannah_B
MYOB Moderator
124 Posts
MYOB Moderator
Australia
MYOB Moderator

124Posts

27Kudos

25Solutions

Re: MS Access VBA MSXML2.ServerXMLHTTP Response Unreadable

Hi @AnthRamDF,

 

Thanks for reaching out, There are a couple of reasons that can cause the error OAuthTokenIsInvalid.

 

I recommend having a look at the support articles below. If this does not resolve the error can you please create a support request with us HERE, And we can have a more in-depth look into what is causing this. 

 

Oauth token is invalid: https://apisupport.myob.com/hc/en-us/articles/360000500035-I-m-getting-the-OAuthTokenIsInvalid-error

 

Refreshing the Access Token: https://apisupport.myob.com/hc/en-us/articles/360000477416-Refreshing-access-tokens-using-the-refres...

 

 


Thanks,
@Hannah_B


MYOB API Specialist


MYOB API Support Centre|MYOB App Marketplace|MYOB AccountRight API Endpoint Doc's



Did my answer help?


Mark it as a Solution

AnthRamDF
3 Posts
User

3Posts

0Kudos

1Solutions

Solved: Go to Solution

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.

Didn't find your answer here?

Try using advanced search to find a post more easily Advanced Search
or
Get the conversation started and make a new post Start a Post