Forum Discussion

CodeMaker's avatar
CodeMaker
Contributing User
5 years ago

ASP.Net Support

Btw, we really need a Developer Board.


An ASP.Net sample would make a massive difference.   Your typical C# sample with OAuth2 does not work for ASP because tokens cannot be kept in memory, and therefore the whole login process requires new access every time.   .Net Core does not hold session variables anymore.

 

I might add, an MVC ASP question has never been successfully answered by MYOB since ODBC was axed.   I suppose many intranet developer have given up asking?

 

The end result is that the C# sample you provide in limiting and does not help with promoting MYOB online connectivity.   This may be good for an App, but is useless in an intranet environment.


Can someone please, at minimum, show how ASP.Net (preferable MVC5 web api minimum) can log into our account and maybe show a list of Suppliers so as to show the transition between one page to another whilst maintaining our tokens?

 

Thank you.

A code sample I have trying to list company accounts is below (MyobOnlineController.cs):

-----------------------------------------------------------------------------------

public ActionResult Index(string code)
{
    OAuthMyob.Server.Code = code;
    ViewData["Error"] = "";
    ViewData["DevPoint"] = "";
    try
    {
      OAuthMyob.Server.Configuration = new ApiConfiguration(OAuthMyob.Setting.Key, OAuthMyob.Setting.Secret, OAuthMyob.Setting.RedirectUri);
      OAuthMyob.Server.OAuthService = new OAuthService(OAuthMyob.Server.Configuration);

      if (string.IsNullOrEmpty(code) || (OAuthMyob.Server.Keystore.OAuthResponse == null && string.IsNullOrEmpty(code)))
      {
        string url = string.Format(
            "{0}?client_id={1}&redirect_uri={2}&scope={3}&response_type=code",
            OAuthMyob.Server.OAuthServer,
            OAuthMyob.Setting.Key,
            HttpUtility.UrlEncode(OAuthMyob.Setting.RedirectUri), 
            OAuthMyob.Server.OAuthScope //"CompanyFile" //"la.global"
        );
        OAuthMyob.Server.OAuthKeyService.OAuthResponse = null;
        Response.Redirect(url);
      }
      else
      {
        if (OAuthMyob.Server.Keystore.OAuthResponse == null)
        {
          OAuthMyob.Server.Tokens = OAuthMyob.Server.OAuthService.GetTokens(code);
          OAuthMyob.Server.Keystore.OAuthResponse = OAuthMyob.Server.Tokens;
        }

        var cfService = new CompanyFileService(OAuthMyob.Server.Configuration, null, OAuthMyob.Server.Keystore);

        CompanyFile[] companyFiles = cfService.GetRange();
        CompanyFile companyFile = companyFiles.FirstOrDefault(c => c.Id == Guid.Parse(OAuthMyob.Setting.CompanyId));
        PagedCollection<Account> accounts = new PagedCollection<Account>();
      }
    }
    catch (Exception ex)
    {
      ViewData["Error"] = ex.ToString();
    }
    return View();
}

  • Hi CodeMaker 

     

    I’ve moved your post onto our API developers board, so that other developers can share their own insight into your issue.

     

    Having checked with the team who provide support for the API they have advised me that the only code samples they provide are the ones on our Developers website. That said I’ve shared your comments and feedback with them.

     

    If you did have any questions relating to the API, I recommend submitting a request on our API support website. Those requests will be seen to and responded by our team who look after the APIs

  • The_Doc's avatar
    The_Doc
    Ultimate Cover User

    Hi CodeMaker 

     

    You really need to send this sort of question to developers@myob.com.au and they will reply - they are pretty good.

     

    However, I think I can answer this for you having gone there been there and tried to do that.

     

    I got both the C#.NET and the VB.NET versions running for local files - no problem and then decided to discard both these and build my own code - I did and it is running beautifully for a local file.

     

    The problem with an online file is the need for authentication - and NO YOU CANNOT automate it - logon passwords will not and cannot be stored. They can be for a local file but not online.

     

    To establish a connection with an online file you must first get an access token WHICH CAN ONLY BE INITIATED MANUALLY with a manual logon and a 2Fa - this token lasts for a week but expries and must be refreshed every 20 mins.

     

    Once you have this access token - refreshing can be automated an no longer requires re-logon.

     

    However, it is this initial logon you are trying to automate - you cannot for security reasons - IT MUST INITIALLY be manual.

     

    I am at that stage of doing that now in my code and then capturing the access token in the https response.

     

    Hope this helps

     

    The Doc

  • Neil_M's avatar
    Neil_M
    Former Staff

    Hi CodeMaker 

     

    I’ve moved your post onto our API developers board, so that other developers can share their own insight into your issue.

     

    Having checked with the team who provide support for the API they have advised me that the only code samples they provide are the ones on our Developers website. That said I’ve shared your comments and feedback with them.

     

    If you did have any questions relating to the API, I recommend submitting a request on our API support website. Those requests will be seen to and responded by our team who look after the APIs