Login() Method
You use the Login() method to make the client application sign in to MYOB Advanced.
Syntax
public LoginResult Login(string name, string password)
Parameters
- name: The username that the application should use to sign in to MYOB Advanced, such as
"admin"
.To sign in to a specific MYOB Advanced tenant, specify the name parameter as follows:
UserName@TenantName
, where you should specify the username instead ofUserName
and the tenant name instead ofTenantName
. For example, if you sign in to the tenant with the name Dollar as the user with the name admin, you should specify the parameter asadmin@Dollar
. You can view the name that should be used for the tenant in the Login Name box of the Tenants (SM203520) form.To sign in to a certain branch in the tenant, specify the parameter as follows:
UserName@TenantName:BranchName
, where you should specify the username instead ofUserName
, the tenant name instead ofTenantName
, and the branch ID instead ofBranchName
. You can view the ID of the branch in the Branch ID box of the Branches (CS102000) form. For example, if you sign in to the East branch of the Dollar tenant as the user with the name admin, you should specify the parameter asadmin@Dollar:East
. - password: The password for the username, such as
"123"
.
Return Value
The method returns the LoginResult object, which contains the description of errors that occurred during signing in, if any.
Example
The following code signs in to MYOB Advanced by using the parameters that are specified in the application settings.
Screen context = new Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = "https://localhost/WebServiceAPITest/Soap/MYSTORE.asmx";
context.Login("admin@MyTenant:MYSTORE", "123");
Usage Notes
- Initialize the CookieContainer property of the object with a new
System.Net.CookieContainer()
. The CookieContainer property is a standard property of an object of theHttpWebClientProtocol
system type. (The Screen class is derived from theHttpWebClientProtocol
class.) This property is used to maintain the session state for a client. - Specify the URL of the web service in the URL property of the object. This is the same URL that you specify when you add a web reference to the MYOB Advanced web service. You can change the URL of the service dynamically in your application if you need to switch between multiple MYOB Advanced web services.
using
(
//Connect to the web services and log in to MYOB Advanced
Screen context = new Screen();
...
)
{
try
{
//Import, export, or submit data
...
}
finally
{
//Log out from MYOB Advanced
context.Logout();
}
}
You should take into account MYOB Advanced license API limits when using the Login() method. For details, see License Restrictions for API Users.