Перейти к содержанию

Аутентификация

Доступ к API осуществляется с помощью JWT-токена. Токен можно получить внутри панели управления GoSMS в разделе API интеграция. Токен необходимо передавать в заголовке каждого запроса в формате:

Authorization: Bearer $GOSMS_TOKEN

Формат примеров API

Примеры в этой документации описаны с помощью curl, HTTP-клиента командной строки. На компьютерах Linux и macOS обычно по умолчанию установлен curl, и он доступен для загрузки на всех популярных платформах, включая Windows.

Примеры

bash  curl -X POST     
    -H "Content-Type: application/json"     
    -H "Authorization: Bearer $GOSMS_TOKEN"     
    -d '{"message":"Test message sms","phone_number":"79999999999"}' "https://api.gosms.ru/v1/sms/send"
import requests
import json
from typing import Dict, Any

def send_sms(message: str, phone_number: str, token: str) -> str:
    """
    Sends an SMS message using the GoSMS API.

    Parameters:
    - message (str): The content of the SMS message to be sent.
    - phone_number (str): The recipient's phone number.
    - token (str): The authorization token for the GoSMS API.

    Returns:
    - str: The response text from the API call.
    """
    url = "https://api.gosms.ru/v1/sms/send"
    payload = json.dumps({
        "message": message,
        "phone_number": phone_number
    })
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {token}'
    }

    response = requests.post(url, headers=headers, data=payload)
    return response.text

if __name__ == "__main__":
    message = "Test message sms"
    phone_number = "79999999999"
    token = "GOSMS_TOKEN"

    response_text = send_sms(message, phone_number, token)
    print(response_text)
<?php
// Create a new HTTP client instance
$client = new http\Client;

// Create a new HTTP request instance
$request = new http\Client\Request;

// Set the request URL and method
$request->setRequestUrl('https://api.gosms.ru/v1/sms/send');
$request->setRequestMethod('POST');

// Create and append the request body with JSON data
$body = new http\Message\Body;
$body->append(json_encode([
    "message" => "Test message sms",
    "phone_number" => "79999999999"
]));
$request->setBody($body);

// Set the request headers, including Content-Type and Authorization
$request->setHeaders([
    'Content-Type' => 'application/json',
    'Authorization' => 'Bearer GOSMS_TOKEN'
]);

// Send the request
$client->enqueue($request)->send();

// Get the response and output the response body
$response = $client->getResponse();
echo $response->getBody();
use reqwest::blocking::Client;
use serde_json::{json, Value};
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    // Define the API endpoint and request method
    let url = "https://api.gosms.ru/v1/sms/send";
    let method = "POST";

    // Create the payload with the message and phone number
    let payload = json!({
        "message": "Test message sms",
        "phone_number": "79999999999"
    });

    // Initialize the HTTP client
    let client = Client::new();

    // Create a new HTTP request with the defined method, URL, and payload
    let mut req = client.request(method, url);
    req = req.json(&payload);
    req = req.header("Content-Type", "application/json");
    req = req.header("Authorization", "Bearer GOSMS_TOKEN");

    // Send the request and get the response
    let res = req.send()?;

    // Read the response body
    let body = res.text()?;

    // Print the response body
    println!("{}", body);

    Ok(())
}
package main

import (
    "fmt"
    "strings"
    "net/http"
    "io/ioutil"
)

func main() {
    // Define the API endpoint and request method
    url := "https://api.gosms.ru/v1/sms/send"
    method := "POST"

    // Create the payload with the message and phone number
    payload := strings.NewReader(`{
        "message": "Test message sms",
        "phone_number": "79999999999"
    }`)

    // Initialize the HTTP client
    client := &http.Client{}

    // Create a new HTTP request with the defined method, URL, and payload
    req, err := http.NewRequest(method, url, payload)
    if err != nil {
        fmt.Println("Error creating request:", err)
        return
    }

    // Add necessary headers to the request
    req.Header.Add("Content-Type", "application/json")
    req.Header.Add("Authorization", "Bearer GOSMS_TOKEN")

    // Send the request and get the response
    res, err := client.Do(req)
    if err != nil {
        fmt.Println("Error sending request:", err)
        return
    }
    defer res.Body.Close()

    // Read the response body
    body, err := ioutil.ReadAll(res.Body)
    if err != nil {
        fmt.Println("Error reading response:", err)
        return
    }

    // Print the response body
    fmt.Println(string(body))
}
const axios = require('axios');

let data = JSON.stringify({
"message": "Test message sms",
"phone_number": "79999999999"
});

let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.gosms.ru/v1/sms/send',
headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer GOSMS_TOKEN'
},
data : data
};

axios.request(config)
.then((response) => {
    console.log(JSON.stringify(response.data));
})
.catch((error) => {
    console.log(error);
});