Thank you for visiting our Partner Zone. This area is an exclusive space for MYOB Partners. Find out how to Partner with MYOB.
August 2021
August 2021
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.
Solved! Go to Solution.
September 2021
September 2021
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
September 2021
September 2021
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.
September 2021
September 2021
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.