OpenAPI Документация
Используйте простой REST API для отправки SMS через Payom.tj. Ниже представлены примеры для популярных языков программирования.
Пример cURL запроса
curl --location 'https://HOST/api/message' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_TOKEN' \
--data '{
"telephone": "+992999999999",
"text": "Привет, это сообщение из Payom.tj",
"senderName": "payom.tj",
"type": "SMS"
}'
Пример запроса на PHP
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://HOST/api/message',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"telephone": "+992999999999",
"text": "Привет, это сообщение из Payom.tj",
"senderName": "payom.tj",
"type": "SMS"
}',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer YOUR_TOKEN'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Пример запроса на Node.js
const axios = require('axios');
let data = JSON.stringify({
"telephone": "+992999999999",
"text": "Привет, это сообщение из Payom.tj",
"senderName": "payom.tj",
"type": "SMS"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://HOST/api/message',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
Пример запроса на Python
import http.client
import json
conn = http.client.HTTPSConnection("HOST")
payload = json.dumps({
"telephone": "+992999999999",
"text": "Привет, это сообщение из Payom.tj",
"senderName": "payom.tj",
"type": "SMS"
})
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
}
conn.request("POST", "/api/message", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Пример запроса на Go
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://HOST/api/message"
method := "POST"
payload := strings.NewReader(`{
"telephone": "+992999999999",
"text": "Привет, это сообщение из Payom.tj",
"senderName": "payom.tj",
"type": "SMS"
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer YOUR_TOKEN")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}