Les APIs de SMSFLOW permettent d'envoyer des SMS de campagne ou marketing
Pour ce faire vous devez disposer d'un compte sur la plateforme. Si vous n'avez pas encore de compte merci de nous contacter
Authentification
Cette API via la méthode POST retourne un token qui sera utilisé dans le header comme clé d'authentification. Le token a une durée de validité de 24H. Les informations a envoyé pour obtenir le token sont les suivants:
- Username (obligatoire)
- password (obligatoire)
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('username', 'xxxxxx');
data.append('password', 'xxxxxx');
var config = {
method: 'post',
url: 'https://sms.tinsight.tech/auth2/get_token_auth/',
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://sms.tinsight.tech/auth2/get_token_auth/"
payload={'username': 'xxxxx','password': 'xxxxxx'}
response = requests.request("POST", url, data=payload)
print(response.text)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.tinsight.tech/auth2/get_token_auth/"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("username", "xxxxx")
_ = writer.WriteField("password", "xxxxxx")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sms.tinsight.tech/auth2/get_token_auth/');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->addPostParameter(array(
'username' => 'xxxxx',
'password' => 'xxxxxx'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
{
"token": "xxxxxxxxxxxxxxxxxxxxxxxxx",
"username": "xxxx",
"code": 200,
"is_admin": false,
"company_name": "xxxxx",
"company_id": 1
}
Envoi de SMS
Grâce à cette API via la méthode POST vous pouvez envoyer des sms à vos clients à. Elle nécessite un token et prend en paramètres :
- number: Le numéro du destionataire (obligatoire)
- sender_id: L'id de l'expediteur (Facultatif) Dans le cas de plusieurs expéditeurs à votre compte
- message: Le message (obligatoire)
- campagn_id: L'id de la campagne (Facultatif)
- planned_date: La date d'envoi du SMS au format unix (Facultatif). Utiliser pour envoyé le sms à une date ultérieur
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('message', 'SMSFLOW c\'est génial');
data.append('number', 'xxxxxx');
var config = {
method: 'post',
url: 'https://sms.tinsight.tech/apiv2/sms/',
headers: {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx',
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://sms.tinsight.tech/apiv2/sms/"
payload={'message': 'SMSFLOW c\'est génial', 'number': 'xxxxxxxxx'}
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.tinsight.tech/apiv2/sms/"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("message", "SMSFLOW c'est génial")
_ = writer.WriteField("number", "XXXXXXXXX")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token xxxxxxxxxxxxxxxxxxxxxxxxx")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sms.tinsight.tech/apiv2/sms/');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
));
$request->addPostParameter(array(
'message' => 'SMSFLOW c\'est génial',
'number' => 'XXXXXXXXX'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
{
"message": "success",
"code": 200,
"sms_id": "SMS5253043",
"status": "Reçu",
"total_sms": 1,
"planned_date": ""
}
SMS infos
Dans le cas ou vous voulez récupérer les informations concernant un sms, il suffit de faire appel à cette API via une requête GET Le paramètre à envoyer est :
- id : L'ID du sms (Facultatif)
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
var config = {
method: 'get',
url: 'https://sms.tinsinght.tech/apiv2/sms/?id=SMS0000001',
headers: {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx',
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://sms.tinsight.tech/apiv2/sms/?id=SMS0000001"
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.tinsight.tech/apiv2/sms/?id=SMS0000001"
method := "GET"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token xxxxxxxxxxxxxxxxxxxxxxxxx")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sms.tinsight.tech/apiv2/sms/?id=SMS0000001');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
{
"data": [
{
"sms_id": "SMS0000001",
"creation_date": "xx-xx-xxxx xx:xx:xx",
"numero_destinataire": "XXXXXXXXXXXX",
"total_sms": "1",
"campagne": null,
"status": 1,
"sender": "smsflow",
"planned_date": "",
"status_name": "Reçu"
}
]
}
Code de vérification
Certains système nécessite une vérification en 2 étapes afin de pouvoir authentifier un numéro de téléphone. Cette vérification se fait par l'envoi et la confirmation d'un code par sms. A travers ses APIs SMSFLOW offre déjà une solution clé en main.
Envoi du code
Cette api permet d'envoyer un code à un utilisateur via SMS . Elle utilise la méthode POST Les paramètres à envoyer sont :- phone_number: Le numéro de téléphone du client (Obligatoire)
- timeout: La durée de validité du code en seconde (facultatif par défaut 15 mn)
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('phone_number', 'XXXXXXXXX');
var config = {
method: 'post',
url: 'https://sms.tinsight.tech/apiv2/smscode/',
headers: {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx',
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://sms.tinsight.tech/apiv2/smscode/"
payload={'phone_number': 'XXXXXXXXX'}
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.tinsight.tech/apiv2/smscode/"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("phone_number", "XXXXXXXXX")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token xxxxxxxxxxxxxxxxxxxxxxxxx")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sms.tinsight.tech/apiv2/smscode/');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
));
$request->addPostParameter(array(
'phone_number' => 'XXXXXXXXX'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
{
"id": 11,
"code": "422510",
"status": "Envoyé",
"numero": "XXXXXXXXX"
}
Vérification du code
Cette API via la méthode POST permet de vérifier un code précédemment envoyé. Les paramètres à envoyer sont les suivants:- phone_number: Le numéro de téléphone du client (Obligatoire)
- code: le code de validation (Obligatoire)
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('phone_number', 'XXXXXXXXX');
data.append('code', 'XXXXXX');
var config = {
method: 'post',
url: 'https://sms.tinsight.tech/apiv2/verify_code/',
headers: {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://sms.tinsight.tech/apiv2/verify_code/"
payload={'phone_number': 'XXXXXXXXX','code': 'XXXXXX'}
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.tinsight.tech/apiv2/verify_code/"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("phone_number", "XXXXXXXXX")
_ = writer.WriteField("code", "XXXXXX")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token xxxxxxxxxxxxxxxxxxxxxxxxx")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sms.tinsight.tech/apiv2/verify_code/');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
));
$request->addPostParameter(array(
'phone_number' => 'XXXXXXXXX',
'code' => 'XXXXXX'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
{
"code": 200,
"message": "Le code a été validé"
}
Liste / Statut d'un code
Cette API via la méthode GET permet lister les codes envoyés ou de verifier le statut d'un code Le paramètres à envoyer est:- id: L'identifiant du code (Facultatif)
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('phone_number', 'XXXXXXXXX');
var config = {
method: 'get',
url: 'https://sms.tinsight.tech/apiv2/smscode/?id=11',
headers: {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx',
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://sms.tinsight.tech/apiv2/smscode/?id=11"
payload={'phone_number': 'XXXXXXXXX'}
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.tinsight.tech/apiv2/smscode/?id=11"
method := "GET"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("phone_number", "XXXXXXXXX")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token xxxxxxxxxxxxxxxxxxxxxxxxx")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sms.tinsight.tech/apiv2/smscode/?id=1');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
));
$request->addPostParameter(array(
'phone_number' => 'XXXXXXXXX'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
{
"data": [
{
"id": 11,
"code": 422510,
"timeout": 900,
"status_name": "Envoyé",
"phone_number": "XXXXXXXXX"
}
]
}
Consulter le solde
Cette API via la méthode GET permet de voir le solde actuel de son compte sms
var axios = require('axios');
var config = {
method: 'get',
url: 'https://sms.tinsight.tech/apiv2/balance/',
headers: {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
}
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://sms.tinsight.tech/apiv2/balance"
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://sms.tinsight.tech/apiv2/balance"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token xxxxxxxxxxxxxxxxxxxxxxxxx")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sms.tinsight.tech/apiv2/balance');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Token xxxxxxxxxxxxxxxxxxxxxxxxx'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
{
"balance": 41158,
"partner": "xxxxxx"
}