Desktop Solution in VB using AccountRight API

This thread is now closed to new comments.
Some of the links and information provided in this thread may no longer be available or relevant.
If you have a question please start a new post.
Former Staff
141 Posts
Former Staff
Former Staff




Re: Desktop Solution in VB using AccountRight API

Hi there @Henzard,


In this set of code the exRefresh exception should contain a little more information about the error including an 'errors' field. I'd recommend looking into that variable with your debugger to figure out what the error is.


If you're still having trouble, can you share some screenshots of your debugging to the support team via and we can take a closer look there.




Jack Skinner
MYOBapi Evangelist

Are you a developer? Check out
Looking for an Add-on? Check out
1 Post




Desktop Solution in VB using AccountRight API



We createted a desktop app and need the login to persist over time we really need some help with the code. We are saving the auth token in a DB as a json serialized token and then load it up before doing a trasaction. When it expires we renew it but for some reason it need to do a fresh login every few days. Can someone please help.


'Initialising the Connection 

myConfiguration = New ApiConfiguration(DeveloperKey, DeveloperSecret, "http://desktop")
myOAuthKeyService = New OAuthKeyService()


'Loading from the DB

Dim authTokens As New OAuthTokens
If (mobjConfig.MYOBToken IsNot Nothing AndAlso mobjConfig.MYOBToken.Length > 0) Then
authTokens = Newtonsoft.Json.JsonConvert.DeserializeObject(Of OAuthTokens)(mobjConfig.MYOBToken)
End If


'Setting the Token
Dim oauthService As New OAuthService(myConfiguration)
myOAuthKeyService.OAuthResponse = authTokens


'Check if it's Expired

If myOAuthKeyService.OAuthResponse.HasExpired = True Then

       Dim _oauthService As New OAuthService(myConfiguration)
       Dim _tokens As New OAuthTokens
       Dim _bolError As Boolean = False
       'Try and refresh tokens first ...

              _tokens = oauthService.RenewTokens(myOAuthKeyService.OAuthResponse)
              _bolError = False
       Catch exRefresh As Exception
              _bolError = True 'How do I prevent This ???

       End Try

       'If it does not refresh create a new token 

       If _bolError = True Then
                     _tokens = oauthService.GetTokens(OAuthLogin.GetAuthorizationCode(myConfiguration))
                     _bolError = False
              Catch exNewToken As Exception
                     _bolError = True

              End Try

       End If

       myOAuthKeyService.OAuthResponse = _tokens
       Dim strTokens As String = JsonConvert.SerializeObject(_tokens)

       mobjConfig.MYOBToken = strTokens
End If


Kind Regards

Remember I consult on a per hour basis. Contact me if your need me to fix the problem. $45 per hour.

We can do a 30 min free consultation via Skype.

Henzard Kruger
Certified Advisor and Full Stack developer
Picahoo cc - 0711304241 -
Skype: henzard, Gtalk:
Quality is remembered long after the price is forgotten

I abide by the 3 message rule. After 3 messages we skype.


Didn't find your answer here?

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