C#
Requirements
Make sure you have imported the following namespaces
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Sending Single SMS
var jwtToken = "YOUR JWT TOKEN";
var phone = "0912*******";
var message = "Hi, there";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
var data = new
{
phoneNumber = phone,
message = message
};
var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.bitel.rest/api/v2/sms/single", content);
var responseStr = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<JObject>(responseStr);
if (response.StatusCode != HttpStatusCode.OK)
{
Console.WriteLine("error: {0}", result["error"]);
}
else
{
var result = result["result"];
Console.WriteLine("result is: {0}", result);
}
}
Sending Peer to Peer SMS
var jwtToken = "YOUR JWT TOKEN";
var phones = new[] { "0912*******", "0912*******" };
var messages = new[] { "Hi, there", "hello" };
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
var data = new
{
phoneNumbers = phones,
messages = messages
};
var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.bitel.rest/api/v2/sms/batch/p2p", content);
var responseStr = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<JObject>(responseStr);
if (response.StatusCode != HttpStatusCode.OK)
{
Console.WriteLine("error: {0}", result["error"]);
}
else
{
var result = result["result"];
Console.WriteLine("result is: {0}", result);
}
}
Sending OTP Code
var jwtToken = "YOUR JWT TOKEN";
var phone = "0912*******";
var text = "1234";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
var data = new
{
phoneNumber = phone,
text = text
};
var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.bitel.rest/api/v2/voice/otp", content);
var responseStr = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<JObject>(responseStr);
if (response.StatusCode != HttpStatusCode.OK)
{
Console.WriteLine("error: {0}", result["error"]);
}
else
{
var result = result["result"];
Console.WriteLine("result is: {0}", result);
}
}
Make Single Call
var jwtToken = "YOUR JWT TOKEN";
var phones = "0912*******";
var voiceId = "08e815cbcd724386805103ac0d45e4c2";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
var data = new
{
phoneNumber = phones,
voiceId = voiceId
};
var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.bitel.rest/api/v2/voice/single", content);
var responseStr = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<JObject>(responseStr);
if (response.StatusCode != HttpStatusCode.OK)
{
Console.WriteLine("error: {0}", result["error"]);
}
else
{
var result = result["result"];
Console.WriteLine("result is: {0}", result);
}
}
Last updated