using System; using System.IO; using System.Text; public static void Main() { //-- Intent: Update the hotline configuration profile for the hotline phone number of (866) 802-0837 --// //-- PUT to the following url --// string my_url = "http://api.v4.swiftreach.com/api/Hotlines/Update"; //-- our API KEY credentials --// string API_KEY = "12345"; UriBuilder my_uri = new UriBuilder(my_url); my_uri.Port = 80; System.Net.HttpWebRequest MyRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(my_uri.Uri); //-- Update Email is a PUT --// MyRequest.Method = "PUT"; //-- Append the API KEY header --// MyRequest.Headers.Add("SwiftAPI-Key", API_KEY); //-- build the Email_Message XML to POST --// string create_email = "<HotLineProfile xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema/SwiftReach.Swift911.Core.Hotline\">" +"<BusinessHours>" +"<BusinessHours>" +"<BeginTime></BeginTime>" +"<EndTime></EndTime>" +"<HoursType>Always_Open</HoursType>" +"<WeekDay>Sunday</WeekDay>" +"</BusinessHours>" +"<BusinessHours>" +"<BeginTime></BeginTime>" +"<EndTime></EndTime>" +"<HoursType>Always_Open</HoursType>" +"<WeekDay>Monday</WeekDay>" +"</BusinessHours>" +"<BusinessHours>" +"<BeginTime></BeginTime>" +"<EndTime></EndTime>" +"<HoursType>Always_Open</HoursType>" +"<WeekDay>Tuesday</WeekDay>" +"</BusinessHours>" +"<BusinessHours>" +"<BeginTime></BeginTime>" +"<EndTime></EndTime>" +"<HoursType>Always_Open</HoursType>" +"<WeekDay>Wednesday</WeekDay>" +"</BusinessHours>" +"<BusinessHours>" +"<BeginTime></BeginTime>" +"<EndTime></EndTime>" +"<HoursType>Always_Open</HoursType>" +"<WeekDay>Thursday</WeekDay>" +"</BusinessHours>" +"<BusinessHours>" +"<BeginTime></BeginTime>" +"<EndTime></EndTime>" +"<HoursType>Always_Open</HoursType>" +"<WeekDay>Friday</WeekDay>" +"</BusinessHours>" +"<BusinessHours>" +"<BeginTime></BeginTime>" +"<EndTime></EndTime>" +"<HoursType>Always_Open</HoursType>" +"<WeekDay>Saturday</WeekDay>" +"</BusinessHours>" +"</BusinessHours>" +"<ClosedSettings i:type=\"Hotline_Voice\">" +"<ConfigType>Voice</ConfigType>" +"<VoiceCode>659377</VoiceCode>" +"<VoiceType>user_defined_voice_message</VoiceType>" +"</ClosedSettings>" +"<HolidayHours i:nil=\"true\" />" +"<OpenSettings i:type=\"Hotline_Voice\">" +"<ConfigType>Voice</ConfigType>" +"<VoiceCode>659377</VoiceCode>" +"<VoiceType>user_defined_voice_message</VoiceType>" +"</OpenSettings>" +"<Active>true</Active>" +"<ChangeStamp>3/20/2013 3:25:52 PM</ChangeStamp>" +"<ChangedByUser>sample</ChangedByUser>" +"<Code>100037</Code>" +"<CreateStamp>3/11/2013 9:31:00 AM</CreateStamp>" +"<CreatedByUser>sample</CreatedByUser>" +"<CustomerCode>200201</CustomerCode>" +"<JobCode>0</JobCode>" +"<Name>V4 Nick</Name>" +"<PhoneNumber>8668020837</PhoneNumber>" +"</HotLineProfile>"; //-- PUt the xml --// byte[] bytes = System.Text.Encoding.ASCII.GetBytes(create_email); MyRequest.ContentLength = bytes.Length; MyRequest.ContentType = "text/xml; encoding='utf-8'"; Stream s = MyRequest.GetRequestStream(); s.Write(bytes, 0, bytes.Length); s.Close(); try { //-- get the response --// System.Net.HttpWebResponse MyResponse = (System.Net.HttpWebResponse)MyRequest.GetResponse(); string message = String.Format("Received HTTP {0}", MyResponse.StatusCode); using (StreamReader sr = new StreamReader(MyResponse.GetResponseStream())) { //-- Create was successful --// string response_body = sr.ReadToEnd(); System.Console.WriteLine("SUCCESS - " + response_body); } } catch (System.Net.WebException webEx) { //-- Create failed --// using (StreamReader sr = new StreamReader(webEx.Response.GetResponseStream())) { string response_body = sr.ReadToEnd(); string error_message = String.Format("Received HTTP {0} : {1}", webEx.Status.ToString(), response_body); System.Console.WriteLine("ERROR - " + error_message); } } }