Exemple API SMS Rust


extern crate reqwest;
#[macro_use]
extern crate serde_json;

use reqwest::Client;

fn main() -> Result<(), reqwest::Error> {

    let payload = json!({
        "sms": {
            "message": {
                "text": "Hello Rust !",
                "sender": "Rust",
            },
            "recipients": {
                "gsm":[
                    {
                        "value": "41781234567",
                    }
                ]
            }
        }
    });

    println!("{}", payload.to_string());

    let request_url = "https://api.smsup.ch/send";
    let token = "your.token"; //Your first token must be generated on our plateform at https://app.smsup.ch/developers/api-tokens
    let response = Client::new()
        .post(request_url)
        .header("Accept", "application/json")
        .header("Authorization", format!("{}{}", "Bearer ", token))
        .json(&payload)
        .send()?
        .text()?;

    println!("{:#?}", response);

    Ok(())
}