We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

SMS integration using c#asp.net

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
keshs3
Posts: 7
Joined: Thu Dec 15, 2016 11:55 am

SMS integration using c#asp.net

Post by keshs3 »

Trying to integrate SMS functionality. Sample code below. Both xml and json calls are not working

protected void Page_Load(object sender, EventArgs e)
{
string messagexml = "<sms_message>" +
"<sms_message_id>"+Guid.NewGuid()+"</sms_message_id><to>16xxxxx4277</to><from>6xxxxx7275</from><body>your confirmation number is 12345678765432</body><request_timestamp>"
+ "1491973998</request_timestamp><result_url><result_url><status>queued</status></sms_message>";
string destination = "http://hosting.plumgroup.com/ws/sms/queue.xml";
postXMLData( destination, messagexml);

string JsonData = @"{""object"":{""to"":""16xxxx94277"",""from"":""6xxxxx7275"",""body"":""Testing from VOX Telehealth."",""result_url"":""""}}";

CreateJsonCall(destination, JsonData);
}

public string postXMLData(string destinationUrl, string requestXml)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
request.Credentials= new NetworkCredential("uname", "pwd");
byte[] bytes;
bytes = System.Text.Encoding.ASCII.GetBytes(requestXml);
request.ContentType = "text/xml";
request.ContentLength = bytes.Length;
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Flush();
requestStream.Close();

//HttpWebResponse response;
//response = (HttpWebResponse)request.GetResponse();
//if (response.StatusCode == HttpStatusCode.OK)
//{
// Stream responseStream = response.GetResponseStream();
// string responseStr = new StreamReader(responseStream).ReadToEnd();
// return responseStr;
//}
return null;
}


public void CreateJsonCall(string URL, string DATA)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Credentials = new NetworkCredential("usename", "pwd");
request.Method = "POST";
request.ContentType = " application/x-www-form-urlencoded";
request.ContentLength = DATA.Length;
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
requestWriter.Write(DATA);
requestWriter.Close();



}

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: SMS integration using c#asp.net

Post by support »

Hi,

The SMS REST API takes in the following POST parameters:

* to
* from
* body
* result_url (optional)

The parameters you are trying to use are the response parameters the API will send back to you after you make the call.

Please refer to the documentation for more details: http://www.plumvoice.com/docs/dev/plumd ... _sms_queue

Regards,
Plum Support

keshs3
Posts: 7
Joined: Thu Dec 15, 2016 11:55 am

Re: SMS integration using c#asp.net

Post by keshs3 »

support wrote: The SMS REST API takes in the following POST parameters:

* to
* from
* body
* result_url (optional)
I am trying to send those 4 params in my json object.

string JsonData = @"{""object"":{""to"":""16xxxx94277"",""from"":""6xxxxx7275"",""body"":""Testing from VOX Telehealth."",""result_url"":""""}}";

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: SMS integration using c#asp.net

Post by support »

Hi,

The POST request you are trying to make should be in x-www-form-urlencoded format, not in JSON or XML format.

Code: Select all

to=18005555555&from=18005550000&body=thisisatest
Unfortunately, we are not familiar with C#/ASP.NET, but an example in php would be:

Code: Select all

$url = 'http://hosting.plumgroup.com/ws/sms/queue.json';
$fields = array(
	'to' => urlencode("18005555555"),
	'from' => urlencode("18005550000"),
	'body' => urlencode("thisisatest"),
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

$result = curl_exec($ch);

curl_close($ch);
Regards,
Plum Support

Post Reply