ASP.Net Support

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.
CodeMaker
Contributing User
6 Posts
Contributing User
Contributing User

6Posts

0Kudos

1Solutions

Solved: Go to Solution

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();
}

2 REPLIES 2
Neil_M
13,473 Posts
Former Staff
Former Staff

13,473Posts

0Kudos

1,916Solutions

Accepted Solution Solved

Re: ASP.Net Support

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

Regards,
Neil

MYOB Community Support

Online Help| Forum Search| my.MYOB| Download Page

Did my answer help?

Mark it as a SolutionHelpful? Leave a to tell others

The_Doc
Ultimate Partner
1,537 Posts
Ultimate Partner
Australia
Ultimate Partner

1,537Posts

165Kudos

162Solutions

Re: ASP.Net Support

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

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