public static void Main() { // demonstrates how to intellegently get the zone information. // autotask will tell you which zone URL to use based on the userID var client = new ATWSSoapClient (); zoneInfo = client.getZoneInfo (auth_user_id); Console.WriteLine ("ATWS Zone Info: \n\n" + "URL = " + zoneInfo.URL); // Create the binding. // must use BasicHttpBinding instead of WSHttpBinding // otherwise a "SOAP header Action was not understood." is thrown. BasicHttpBinding myBinding = new BasicHttpBinding (); myBinding.Security.Mode = BasicHttpSecurityMode.Transport; myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; // Must set the size otherwise //The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. myBinding.MaxReceivedMessageSize = 2147483647; // Create the endpoint address. EndpointAddress ea = new EndpointAddress (zoneInfo.URL); client = new ATWSSoapClient (myBinding, ea); client.ClientCredentials.UserName.UserName = auth_user_id; client.ClientCredentials.UserName.Password = auth_user_password; // query for any account. This should return all accounts since we are retreiving anything greater than 0. StringBuilder sb = new StringBuilder (); sb.Append ("<queryxml><entity>Account</entity>").Append (System.Environment.NewLine); sb.Append ("<query><field>id<expression op=\"greaterthan\">0</expression></field></query>").Append (System.Environment.NewLine); sb.Append ("</queryxml>").Append (System.Environment.NewLine); // have no clue what this does. AutotaskIntegrations at_integrations = new AutotaskIntegrations (); // this example will not handle the 500 results limitation. // Autotask only returns up to 500 results in a response. if there are more you must query again for the next 500. var r = client.query (at_integrations, sb.ToString ()); Console.WriteLine ("response ReturnCode = " + r.ReturnCode); if (r.ReturnCode == 1) { if (r.EntityResults.Length > 0) { foreach (var item in r.EntityResults) { Account acct = (Account)item; Console.WriteLine ("Account Name = " + acct.AccountName); Console.WriteLine ("Account number = " + acct.AccountNumber); } } } Console.ReadLine (); }
public static void Main() { var client = new ATWSSoapClient (); zoneInfo = client.getZoneInfo (auth_user_id); Console.WriteLine ("ATWS Zone Info: \n\n" + "URL = " + zoneInfo.URL); // Create the binding. // must use BasicHttpBinding instead of WSHttpBinding // otherwise a "SOAP header Action was not understood." is thrown. BasicHttpBinding myBinding = new BasicHttpBinding (); myBinding.Security.Mode = BasicHttpSecurityMode.Transport; myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; // Must set the size otherwise //The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. myBinding.MaxReceivedMessageSize = 2147483647; // Create the endpoint address. EndpointAddress ea = new EndpointAddress (zoneInfo.URL); client = new ATWSSoapClient (myBinding, ea); client.ClientCredentials.UserName.UserName = auth_user_id; client.ClientCredentials.UserName.Password = auth_user_password; // query for any account. This should return all accounts since we are retreiving anything greater than 0. StringBuilder sb = new StringBuilder (); //sb.Append ("<queryxml><entity>Account</entity>").Append (System.Environment.NewLine); //sb.Append ("<query><field>id<expression op=\"greaterthan\">0</expression></field></query>").Append (System.Environment.NewLine); //sb.Append ("</queryxml>").Append (System.Environment.NewLine); sb.Append("<queryxml><entity>Ticket</entity>").Append(System.Environment.NewLine); sb.Append("<query>").Append(System.Environment.NewLine); sb.Append("<field>TicketNumber<expression op=\"Equals\">T20130623.0113</expression>").Append(System.Environment.NewLine); sb.Append("</field>").Append(System.Environment.NewLine); //sb.Append("T20130623.0113").Append(System.Environment.NewLine); sb.Append("</query></queryxml>").Append(System.Environment.NewLine); Console.WriteLine("Output the query string: {0}", sb.ToString()); // have no clue what this does. AutotaskIntegrations at_integrations = new AutotaskIntegrations (); // this example will not handle the 500 results limitation. // Autotask only returns up to 500 results in a response. if there are more you must query again for the next 500. var r = client.query (at_integrations, sb.ToString ()); Console.WriteLine ("response ReturnCode = " + r.ReturnCode); if (r.ReturnCode == 1) { if (r.EntityResults.Length > 0) { foreach (var item in r.EntityResults) { //Account acct = (Account)item; //Console.WriteLine ("Account Name = " + acct.AccountName); //Console.WriteLine ("Account number = " + acct.AccountNumber); Ticket ticket = (Ticket)item; Console.WriteLine("Ticket Number =" + ticket.TicketNumber); Console.WriteLine("Ticket Note =" + ticket.Description); Console.WriteLine("Ticket Date =" + ticket.CreateDate); Console.WriteLine("Tictet Status =" + ticket.Status); ticket.Description = "Stephen Chen update this ticket at 1/16/2013 to make sure the update function is actually working correctly"; //Ticket[] ticketarr = new Ticket[1]; //ticketarr[0] = ticket; //var result = client.update(at_integrations, ticketarr); //Console.WriteLine("response return code = " + result.ReturnCode); } } } Console.ReadLine (); }
/// <summary> /// Initializes a new instance of the <see cref="AutotaskApiTests"/> class. /// </summary> /// <param name="user">The username.</param> /// <param name="pass">The password.</param> public AutotaskApiTests(string user, string pass, string trackingId) { this.atwsServices = new ATWS { Url = this.webServiceBaseApiUrl }; try { ATWSZoneInfo zoneInfo = this.atwsServices.getZoneInfo(user); if (zoneInfo.ErrorCode >= 0) { string urlZone = zoneInfo.URL; this.atwsServices = new ATWS { Url = urlZone }; NetworkCredential credentials = new NetworkCredential(user, pass); CredentialCache cache = new CredentialCache { { new Uri(this.atwsServices.Url), "Basic", credentials } }; this.atwsServices.Credentials = cache; this.atwsServices.AutotaskIntegrationsValue = new AutotaskIntegrations { IntegrationCode = trackingId }; } else { throw new Exception("Error with getZoneInfo()"); } } catch (Exception exception) { throw new Exception("Error with getZoneInfo()- error: " + exception.Message); } }
/// <summary> /// Creates the ATWS client for the API. /// </summary> /// <returns>The ATWS client.</returns> private ATWS GetClient() { string username = ConfigurationManager.AppSettings["Username"]; string password = ConfigurationManager.AppSettings["Password"]; ATWS service = new ATWS { Url = ConfigurationManager.AppSettings["BaseURL"] }; try { ATWSZoneInfo zoneInfo = service.getZoneInfo(username); string urlZone = zoneInfo.URL; service = new ATWS { Url = urlZone }; NetworkCredential credentials = new NetworkCredential(username, password); CredentialCache cache = new CredentialCache { { new Uri(service.Url), "Basic", credentials } }; service.Credentials = cache; } catch (Exception exception) { throw new Exception("Error creating web service: " + exception.Message); } return(service); }
/// <summary> /// Public Constuctor for API. /// </summary> /// <param name="uri">Contains the Autotask API Service URI</param> /// <param name="user">Contains the Autotask API Service username</param> /// <param name="pass">Contains the Autotask API Service password</param> public AutotaskAPI(string uri, string user, string pass) { string zoneURL = string.Empty; this._atwsServices = new AutotaskApiService_1_5(); this._atwsServices.Url = uri; CredentialCache cache = new CredentialCache(); cache.Add(new Uri(this._atwsServices.Url), "BASIC", new NetworkCredential(user, pass)); this._atwsServices.Credentials = cache; try { ATWSZoneInfo zoneInfo = new ATWSZoneInfo(); zoneInfo = this._atwsServices.getZoneInfo(user); if (zoneInfo.ErrorCode >= 0) { zoneURL = zoneInfo.URL; this._atwsServices = new AutotaskApiService_1_5(); this._atwsServices.Url = zoneInfo.URL; cache = new CredentialCache(); cache.Add(new Uri(this._atwsServices.Url), "BASIC", new NetworkCredential(user, pass)); this._atwsServices.Credentials = cache; } else { throw new Exception("Error with getZoneInfo()"); } } catch (Exception ex) { throw new Exception("Error with getZoneInfo()- error: " + ex.Message); } }
public static void Main() { // demonstrates how to intellegently get the zone information. // autotask will tell you which zone URL to use based on the userID var client = new ATWSSoapClient(); zoneInfo = client.getZoneInfo(auth_user_id); Console.WriteLine("ATWS Zone Info: \n\n" + "URL = " + zoneInfo.URL); // Create the binding. // must use BasicHttpBinding instead of WSHttpBinding // otherwise a "SOAP header Action was not understood." is thrown. BasicHttpBinding myBinding = new BasicHttpBinding(); myBinding.Security.Mode = BasicHttpSecurityMode.Transport; myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; // Must set the size otherwise //The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. myBinding.MaxReceivedMessageSize = 2147483647; // Create the endpoint address. EndpointAddress ea = new EndpointAddress(zoneInfo.URL); client = new ATWSSoapClient(myBinding, ea); client.ClientCredentials.UserName.UserName = auth_user_id; client.ClientCredentials.UserName.Password = auth_user_password; // query for any account. This should return all accounts since we are retreiving anything greater than 0. StringBuilder sb = new StringBuilder(); sb.Append("<queryxml><entity>Account</entity>").Append(System.Environment.NewLine); sb.Append("<query><field>id<expression op=\"greaterthan\">0</expression></field></query>").Append(System.Environment.NewLine); sb.Append("</queryxml>").Append(System.Environment.NewLine); // have no clue what this does. AutotaskIntegrations at_integrations = new AutotaskIntegrations(); // this example will not handle the 500 results limitation. // Autotask only returns up to 500 results in a response. if there are more you must query again for the next 500. var r = client.query(at_integrations, sb.ToString()); Console.WriteLine("response ReturnCode = " + r.ReturnCode); if (r.ReturnCode == 1) { if (r.EntityResults.Length > 0) { foreach (var item in r.EntityResults) { Account acct = (Account)item; Console.WriteLine("Account Name = " + acct.AccountName); Console.WriteLine("Account number = " + acct.AccountNumber); } } } Console.ReadLine(); }
/// <summary> /// The submitButton_Click method. /// </summary> /// <param name="sender">The Sender.</param> /// <param name="e">The EventArgs.</param> protected void SubmitButtonClick(object sender, EventArgs e) { this.error.Visible = false; string email = this.exampleInputEmail.Text; ArrayList emails = (ArrayList)this.Session["Emails"]; List <Contact> contacts = (List <Contact>) this.Session["Contacts"]; if (string.IsNullOrEmpty(email) || !emails.Contains(email)) { this.error.Visible = true; this.error.InnerText = "Email doesn't exist in the database."; return; } if (!this.exampleInputFile.HasFile) { this.error.Visible = true; this.error.InnerText = "Please select a file to upload."; return; } Contact contact = contacts.Find(c => c.EMailAddress.ToString().Equals(email)); Account account = GetAccount(contact.AccountID); Attachment attachment = new Attachment { Info = new AttachmentInfo { FullPath = this.exampleInputFile.FileName, ParentID = contact.AccountID, ParentType = 1, // Account Publish = 1, // All Autotask Users Title = this.exampleInputFile.FileName, Type = "FILE_ATTACHMENT" }, Data = this.exampleInputFile.FileBytes }; long result = client.CreateAttachment(attachment); if (result > 0) { ATWSZoneInfo zoneInfo = client.getZoneInfo(ConfigurationManager.AppSettings["Username"]); this.success.Visible = true; this.accountCommand.NavigateUrl = zoneInfo.WebUrl + "Autotask/AutotaskExtend/ExecuteCommand.aspx?Code=OpenAccount&AccountID=" + attachment.Info.ParentID; this.accountCommand.Text = account?.AccountName.ToString(); } else { this.error.Visible = true; this.error.InnerText = "The file failed to upload. Please try again."; } }
public AutotaskAPIClient(string Username, string Password, AutotaskIntegrationKey IntegrationKey) { if (string.IsNullOrWhiteSpace(Username)) { throw new ArgumentNullException("Username cannot by empty"); } if (string.IsNullOrWhiteSpace(Password)) { throw new ArgumentNullException("Password cannot by empty"); } string _integrationKey = IntegrationKey.GetIntegrationKey(); if (string.IsNullOrWhiteSpace(_integrationKey)) { throw new ArgumentNullException("IntegrationKey cannot by empty"); } _atwsUsername = Username; _atwsPassword = Password; _atwsIntegrationKey = _integrationKey; _atwsIntegrations.IntegrationCode = _integrationKey; NetworkCredential _credential = new NetworkCredential(_atwsUsername, _atwsPassword); try { _atwsHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport) { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue }; _atwsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; _atwsChannelFactory = new ChannelFactory <ATWSSoapChannel>(_atwsHttpBinding, new EndpointAddress(new Uri("https://webservices.autotask.net/ATServices/1.6/atws.asmx"))); _atwsChannelFactory.Credentials.UserName.UserName = _atwsUsername; _atwsChannelFactory.Credentials.UserName.Password = _atwsPassword; _atwsServicesClient = _atwsChannelFactory.CreateChannel(); _atwsServicesClient.Open(); _atwsZoneInfo = _atwsServicesClient.getZoneInfo(_atwsUsername); if (_atwsZoneInfo.ErrorCode >= 0) { _atwsServicesClient.Close(); _atwsChannelFactory.Close(); _atwsChannelFactory = new ChannelFactory <ATWSSoapChannel>(_atwsHttpBinding, new EndpointAddress(new Uri(_atwsZoneInfo.URL))); _atwsChannelFactory.Credentials.UserName.UserName = _atwsUsername; _atwsChannelFactory.Credentials.UserName.Password = _atwsPassword; _atwsServicesClient = _atwsChannelFactory.CreateChannel(); _atwsServicesClient.Open(); if (!Preload()) { throw new Exception("Error with data Preload()"); } } else { throw new Exception("Error with getZoneInfo()"); } } catch { throw new ArgumentException("Username must be invalid, unable to get ZoneInfo"); } }