Search code examples
c#myob

Is ICompanyFileCredentials required when making calls in .net SDK MYOB


I am trying to integrate MYOB .net SDK into my web application (C#). I have some questions about ICompanyFileCredentials. It's the log on credential for a company file. Is it compulsory to submit it when making a call to the service like in this code?

var service = new ItemOrderService(SessionManager.MyConfiguration, null, SessionManager.MyOAuthKeyService);
var list = service.GetRange(SessionManager.SelectedCompanyFile, filter + pageFilter, SessionManager.MyCredentials, null);

I checked the overload methods of many services just to be sure. I can see no overload methods that allow credential to be optional. So I assume this is compulsory. But then again in this link:

https://apisupport.myob.com/hc/en-us/articles/360000576836-Company-file-authentication

And I quoted:

If you get an HTTP 403 "Access Denied" response, you don't yet have permissions to login to that file. This is because some users have not linked their my.myob login with their per-file company file login. You could prompt them to link their login (it's Step 5 of our help guide "Opening a company file"), or you could allow your client to provide their per-file user credentials to your application.

This is kind of confusing for me because it doesn't matter if the users have linked their my.myob login or not, credentials are needed when making calls(at least it is true in .net SDK) as it's a required parameter.

So could someone confirm if the credentials is required when making calls? If yes how do users find out what their company file credentials are cause a lot of times, they don't need to enter them on their desktop? Thanks.


Solution

  • You need to supply two sets of credentials when accessing MYOB SDK

    Here is some sample code from my own work on a MYOB project:

    1) access MYOB to get a list of Companies you have access to, this requires a Developer Key & Secret, and a oAuth key (which is your online account).

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                Configuration = new ApiConfiguration(MYOBModule.DeveloperKey, MYOBModule.DeveloperSecret, MYOBModule.MYOBConfirmationUrl);
                var cfService = new CompanyFileService(Configuration, null, Keys);
    

    Once you've got a list of Companies, you then need to access your individual company via the file username / password

            Credentials = new CompanyFileCredentials(MYOBModule.CompanyFileUsername, MYOBModule.CompanyFilePassword);
    

    So yes you need two sets of authentication.