Forum Discussion
Have you got the access token? Hamishjam
I have not used the class that was uploaded by John_Dinning so I cannot comment on whether it works or not but I have built my own class to get the access token
maybe that was why the class was removed from the online sample but like I said I have not tried using it..
If you have the access token then just create a SimpleOAuthKeyService and assign the values from the token to it and you should be able to run the following.
let me know how you get on. If I have time I'll build a test harness and upload it to github for others that are stuck here...seriously considering leaving the .NET SDK and just using RestSharp/HttpClient to access the API
var keystore = new SimpleOAuthKeyService();
keystore.OAuthResponse = new OAuthTokens
{
AccessToken = myobTokens.AccessToken,
ExpiresIn = int.Parse(myobTokens.ExpiresIn),
ReceivedTime = myobTokens.TokenTime,
RefreshToken = myobTokens.RefreshToken,
Scope = myobTokens.Scope,
TokenType = myobTokens.TokenType
};
// Get Company Files
var cfService = new CompanyFileService(configuration, null, keystore);
var companies = cfService.GetRange();
foreach (var company in companies)
{
System.Console.WriteLine(company.Name);
Debug.WriteLine(company.Name);
}
Thanks for the reply kjm. I have the access tokens and I'm passing them into the SimpleOAuthKeyService.OauthResponse. That side of things is fine. I'm just getting exceptions when trying to fetch the companyfile object with the CompanyFileService from the SDK. I suspect there may be some unexpected json or a breaking .NET 6 change that is yet to be addressed. My next step will be to play with it in an old .NET framework and report it via GitHub I guess.
I'm also leaning towards just pulling the JSON old school style but it would be nice to not have to build that out. MYOB is MIA... Developer site is a jungle of 404's.
- kjm3 years agoTrusted Cover User
I am coding in Winforms/.NET 4.8 and it works fine but I am also leaning towards removing the .NET SDK
- John_Dinning3 years agoTrusted User
Hi kjm,
The OAuthLogin.cs and OAuthKeyService.cs files I posted are used in my project, which is WinForms and .NET 4.8.
It's been most of 10 years since I looked at how they work, but they have done all that time for both local, network and cloud company files.
It does seem odd that MYOB have not fixed the broken links and given access to these files. I'm sure it would be to their advantage.
There have been times when I wished that I had not used the SDK, but it did save me a lot of time and a steep learning curve initially and it has been working fine for our purposes.
- kjm3 years agoTrusted Cover User
thanks for digging out those files..pretty simple stuff there..just builds a webbrowser on a form and listens to the DocumentTitleChanged event of the webrowser and then extracts the code from the document. Means that the solution has to reference Windows.Forms namespace making it a little less 'transportable' instead of just calling the users default browser.
The OAuthKeyService.cs is a little more interesting as it uses IsolatedStorage to actually write the Token to a json file. This is not the path I am heading down. I would not be storing the token anywhere except memory. Not sure why or what the advantages of peristing the token like this is instead of to memory...is this incase user/system closes and then reopens and the user/system can reuse the tokens stored locally as opposed to having to make another call to oauth server?
Anyway I have built a test harness polling the api getting data every minute and it look like the refresh token call is handeld by the SDK. I decompiled the SDK and had a look at MYOB.AccountRight.SDK.Services.ServiceBase and it looks like it handles the expiry/refresh token. Means I just have to get the token once and leave the SDK to it. Nice. Was expecting to have to handle the refresh part myself
Looking for something else?
Search the Community Forum for answers or find your topic and get the conversation started!
Find technical support and help for all MYOB products in our online help centre
Dig into MYOB Academy for free courses, learning paths and live events to help build your business with MYOB.