using System; using System.IO; using System.Text; public static void Main() { //-- Intent: Update a Voice_Message with voicecode 123456 --// //-- PUT to the following url --// string my_url = "http://api.v4.swiftreach.com/api/Messages/Voice/Update/123456"; //-- 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 = "<Message_Profile xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema/SwiftReach.Swift911.Core.Messages.Voice\" xsi:type=\"Voice_Message\">" +"<VoiceCode>123456</VoiceCode>" +"<Name>API Voice Message</Name>" +"<Description>created by api</Description>" +"<DefaultSpokenLanguage>English</DefaultSpokenLanguage>" +"<AutoReplays>1</AutoReplays>" +"<RequireResponse>false</RequireResponse>" +"<ValidResponses/>" +"<EnableAnsweringMachineDetection>false</EnableAnsweringMachineDetection>" +"<EnableAnsweringMachineMessage>false</EnableAnsweringMachineMessage>" +"<CallerID>2012361344</CallerID>" +"<CapacityLimit>0</CapacityLimit>" +"<RingSeconds>60</RingSeconds>" +"<CongestionAttempts>3</CongestionAttempts>" +"<AutoRetries>0</AutoRetries>" +"<AutoRetriesInterval>3</AutoRetriesInterval>" +"<EnableWaterfall>false</EnableWaterfall>" +"<VoiceType>voice_message</VoiceType>" +"<ContentProfile>" +"<VOICE_ALERT_PROFILE>" +"<SpokenLanguage>English</SpokenLanguage>" +"<TTY_Text>This is what I want to show up on a TTY</TTY_Text>' +"<VoiceItem>" +"<VOICE_ALERT_CONTENT>" +"<VoiceItemType>alert_human</VoiceItemType>" +"<AudioSource>" +"<AUDIO_SOURCE xsi:type=\"AUDIO_SOURCE_TTS_TEXT\">" +"<AudioType>audio_source_tts_text</AudioType>" +"<TTSText>This is the message.</TTSText>" +"</AUDIO_SOURCE>" +"</AudioSource>" +"</VOICE_ALERT_CONTENT>" +"</VoiceItem>" +"</VOICE_ALERT_PROFILE>" +"</ContentProfile>" +"</Message_Profile>"; //-- 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); } } }