Example Code

[EXAMPLE CODE INTRO TEXT]

Sending an SMS Message

C#


class SendSMS
{
//Authorization Token from IntelePeer Customer Portal
private string _AUTH_TOKEN = "TOKEN FROM VOICE SERVICES PORTAL";

//API Endpoint for Sending Message
private string _INTP_SEND_MESSAGE = "https://api.intelepeer.com/sms/v1/{0}/send";

public void Send(string toPhoneNumber, string fromPhoneNumber, string message)
{
//Add Phone Number to the URL
StringBuilder sbURI = new StringBuilder();
sbURI.AppendFormat(_INTP_SEND_MESSAGE, fromPhoneNumber);

//Create Content for Request
string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(
new
{
to = toPhoneNumber,
text = message
}
);

System.Net.WebRequest httpWebRequest = System.Net.WebRequest.Create(sbURI.ToString());
//Content Type = application/json; Performing a POST
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
//Add Authorization Token to the Request Header
httpWebRequest.Headers.Add("Authorization", "Bearer " + _AUTH_TOKEN);

//Populate message request
using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}

try
{
//Submit Request and Read Response
System.Net.WebResponse httpResponse = httpWebRequest.GetResponse();

using (System.IO.StreamReader streamReader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
{
string result = streamReader.ReadToEnd();
}
}
catch (System.Net.WebException webException)
{
string response = webException.Message;
}
catch(Exception exception)
{
string response = exception.Message;
}
finally
{
//do something else
}
}
}

PHP

Python

Java

Node.js