SMS integration using c#asp.net

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

  • Author
  • Message
Offline

keshs3

  • Posts: 7
  • Joined: Thu Dec 15, 2016 12:55 pm

SMS integration using c#asp.net

PostThu Apr 13, 2017 1:35 am

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();



}
Offline

support

  • Posts: 3348
  • Joined: Mon Jun 02, 2003 4:47 pm
  • Location: Boston, MA

Re: SMS integration using c#asp.net

PostThu Apr 13, 2017 11:06 am

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/plumdevguide:smsoutbound#queue_sms_rest_api_post_sms_queue

Regards,
Plum Support
Offline

keshs3

  • Posts: 7
  • Joined: Thu Dec 15, 2016 12:55 pm

Re: SMS integration using c#asp.net

PostThu Apr 13, 2017 3:33 pm

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"":""""}}";
Offline

support

  • Posts: 3348
  • Joined: Mon Jun 02, 2003 4:47 pm
  • Location: Boston, MA

Re: SMS integration using c#asp.net

PostThu Apr 13, 2017 3:46 pm

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

Return to Plum DEV Q&A

Who is online

Users browsing this forum: No registered users and 1 guest

cron