# Prerequisite: install the requests module e.g. using pip or easy_install
import requests
api_key = "YOUR_API_KEY"
end_point = "sendsms"
url_args = {
"apiKey": api_key,
"to": "447700900000",
"from": "Firetext",
"message" : "FireText is excellent via Python3 too!"
}
def send_api_message(end_point, url_args):
url = "https://www.firetext.co.uk/api/" + end_point
response = requests.post(url, params = url_args)
return response.text
resp = send_api_message(end_point, url_args)
print (resp)
# Prerequisite: composer require firetext/php-sdk
use FireText\Api;
require 'vendor/autoload.php';
$apiKey = 'YOUR_API_KEY';
$client = new Api\Client(new Api\Credentials\ApiKey($apiKey));
$message = 'FireText is outstanding and really easy to use!';
$from = 'FireText';
$to = '07123456789';
$request = $client->request('SendSms', $message, $from, $to);
$response = $client->execute($request);
$result = $request->response($response);
if($result->isSuccessful()) {
echo "Sent {$result->getCount()} messages".PHP_EOL;
} else {
throw $result->getStatus()->getException();
}
using System;
using System.Net.Http;
using System.Collections.Generic;
/**
* Code designed to work with .net core 2.0+
*/
namespace CSharpApiExample
{
class CSharpApiExample
{
private string apiKey;
private string endPoint;
private static readonly HttpClient client = new HttpClient();
static void Main(string[] args)
{
CSharpApiExample smsSender = new CSharpApiExample();
smsSender.apiKey = "YOUR_API_KEY";
smsSender.endPoint = "sendsms";
Dictionary<string, string> urlArgsArray = new Dictionary<string, string>()
{
{"apiKey", smsSender.apiKey},
{"to", "07700900000"},
{"from", "Firetext"},
{"message", "Sending Firetext sms with c# is simple!"}
};
smsSender.sendApiMessage(smsSender.endPoint, urlArgsArray);
Console.WriteLine("Pending Response ...");
Console.Read();
}
private async void sendApiMessage(string endPoint, Dictionary<string, string> urlArgsArray)
{
var baseUrl = "https://www.firetext.co.uk/api/" + endPoint;
var urlArgs = new FormUrlEncodedContent(urlArgsArray);
var response = await client.PostAsync(baseUrl, urlArgs);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: ");
Console.WriteLine(responseString);
Console.WriteLine("Press any key to continue...");
}
}
}
// Prerequisite: install the request package e.g. npm install request
const request = require('request');
const apiKey = 'YOUR API KEY';
const sendApiMessage = function(endpoint, messageArgs, callback) {
return request.post(
'https://www.firetext.co.uk/api/' + endpoint,
{ form: messageArgs },
callback
);
};
var endpoint = 'sendsms';
var urlArgs = {
'apiKey' : apiKey,
'to' : '447700900000',
'from' : 'Firetext',
'message' : 'Sending sms with Firetext and Node.js is a snap!'
};
sendApiMessage(endpoint, urlArgs, function(error, response, body){
if (error) {
return console.log(error);
}
console.log(body);
});
# Important. Ensure that your version of Ruby is using the latest installation of OpenSSL
require "net/http"
require "uri"
api_key = "YOUR_API_KEY"
def send_api_message(endpoint, url_args)
uri = URI.parse("https://www.firetext.co.uk/api/"+endpoint)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(url_args)
response = http.request(request)
return response
end
data = send_api_message("sendsms",{
"apiKey" => api_key,
"to" => "447700900000",
"from" => "Firetext",
"message" => "Sending Firetext SMS with Ruby is crystal clear!"
})
puts data.body, ""
curl 'https://www.firetext.co.uk/api/sendsms/json' \
-d apiKey='YOUR_API_KEY' \
-d to='447000000000' \
--data-urlencode 'message=Hello from FireText.' \
-d from='FireText'
package main
import ("fmt"; "net/url"; "net/http"; "io/ioutil")
var api_key = "API_KEY_HERE"
func sendApiMessage(endpoint string, parameters url.Values) string {
resp, _ := http.PostForm("https://www.firetext.co.uk/api/"+endpoint, parameters)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return string(body)
}
func main() {
endpoint := "sendsms"
urlArgs := url.Values{
"apiKey": {api_key},
"to": {"447700900000"},
"from": {"FireText"},
"message": {"FireText is excellent via Go too!"},
}
resp := sendApiMessage(endpoint, urlArgs)
fmt.Printf(resp)
}
package uk.firetext;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import java.util.*;
public class Main {
public static final String API_KEY = "API_KEY_HERE";
public static String sendApiMessage(String endpoint, Map urlArgs) throws Exception {
URL url = new URL("https://www.firetext.co.uk/api/"+endpoint);
StringBuilder post = new StringBuilder();
for (Map.Entry param : urlArgs.entrySet()) {
if (post.length() != 0) {
post.append('&');
}
post.append(param.getKey()).append('=').append(URLEncoder.encode(param.getValue(), "UTF-8"));
}
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
conn.getOutputStream().write(post.toString().getBytes());
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
StringBuilder response = new StringBuilder();
for (int c; (c = in.read()) >= 0;) {
response.append((char) c);
}
return response.toString();
}
public static void main(String[] args) {
String endpoint = "sendsms";
Map urlArgs = new HashMap();
urlArgs.put("apiKey", API_KEY);
urlArgs.put("to", "447700900000");
urlArgs.put("from", "FireText");
urlArgs.put("message", "FireText is excellent via Java too!");
try {
String response = sendApiMessage(endpoint, urlArgs);
System.out.println(response);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}