SMS C# API example
using System;
using System.IO;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json;
class Message
{
public string text { get; set; }
public string pushtype { get; set; }
public string sender { get; set; }
public string delay { get; set; }
}
class Phone
{
public string gsmsmsid { get; set; }
public string value { get; set; }
}
class Payload
{
public SMS sms{ get; set; }
public Payload() //default contructor
{
this.sms = new SMS();
}
}
class Recipients
{
public List gsm{ get; set;}
public Recipients()
{
this.gsm = new List();
}
}
class SMS
{
public Message message{ get; set; }
public Recipients recipients{ get; set;}
public SMS()
{
this.recipients = new Recipients();
}
}
public class Program
{
public static void Main()
{
string token = "your.token"; //Your first token must be generated on our plateform at https://my.smsfactor.com/developers/api-tokens
Message msgObj = new Message()
{
text = "Votre message",
pushtype = "alert",
sender = "DOTNET"
};
Phone phoneObj = new Phone()
{
value = "33612345678"
};
Payload payloadObj = new Payload();
payloadObj.sms.message = msgObj;
payloadObj.sms.recipients.gsm.Add(phoneObj);
string jsonData = JsonConvert.SerializeObject(payloadObj);
Console.WriteLine(jsonData);
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.smsfactor.com");
httpWebRequest.Accept = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.Headers.Add("Authorization", "Bearer " + token);
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(jsonData);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine(result);
}
}
}
When to use a C#-based SMS API?
Thanks to our C#-compatible SMS API, you can automate your communications smoothly and efficiently. By integrating SMS sending into your C# applications with just a few lines of code, you greatly simplify your communication processes.
Some typical examples include :
- 2FA to reinforce your users' security.
- Large-scale campaigns to all your customers.
- Transactional notifications: abandonned carts notifications, purchase confirmations, etc.
- Automated or non-automated emergency alerts.
Why choose SMSFactor's SMS C# API?
Choosing the SMSFactor API guarantees you dedicated, personalized technical support. We assist you throughout the integration of our API, providing practical advice and ongoing technical support.
Our SMS API in C# is robust and secure, ensuring 99.9% uptime. We strictly comply with RGPD standards for data protection, and have implemented anti-flood measures to prevent unwanted SMS sending.
Discover the advanced features of our API, which evolves according to your needs:
- Webhooks for retrieving and managing data linked to SMS dispatches.
- Send simulation to test your configurations without impacting end-users.
- Insertion of traced short links to track and optimize generated traffic.
- Receipt of SMS responses and acknowledgements for accurate tracking.
- Automatic unsubscribe management to respect your contacts' preferences.