Sample code for 30+ languages & platforms
Rust

Twilio List Log Messages

See more Twilio Examples

Fetch the log containing information about SMS messages previously sent (or failed to be sent).

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

// Implements the following CURL command:

// curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json?PageSize=20' \
// -u TWILIO_ACCOUNT_SID:TWILIO_AUTH_TOKEN

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

http.set_login("TWILIO_ACCOUNT_SID");
http.set_password("TWILIO_AUTH_TOKEN");

let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json?PageSize=20", &sb_response_body).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let json = chilkat::JsonObject::new();
let _ = json.load_sb(&sb_response_body);
json.set_emit_compact(false);

println!("Response Body:");
println!("{}", json.emit().unwrap_or_default());

let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", http.last_header());
    println!("Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "end": 1,
//   "first_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0",
//   "next_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=1&PageToken=PAMMc26223853f8c46b4ab7dfaa6abba0a26",
//   "page": 0,
//   "page_size": 2,
//   "previous_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0",
//   "messages": [
//     {
//       "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
//       "api_version": "2010-04-01",
//       "body": "testing",
//       "date_created": "Fri, 24 May 2019 17:44:46 +0000",
//       "date_sent": "Fri, 24 May 2019 17:44:50 +0000",
//       "date_updated": "Fri, 24 May 2019 17:44:50 +0000",
//       "direction": "outbound-api",
//       "error_code": null,
//       "error_message": null,
//       "from": "+12019235161",
//       "messaging_service_sid": null,
//       "num_media": "0",
//       "num_segments": "1",
//       "price": "-0.00750",
//       "price_unit": "USD",
//       "sid": "SMded05904ccb347238880ca9264e8fe1c",
//       "status": "sent",
//       "subresource_uris": {
//         "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMded05904ccb347238880ca9264e8fe1c/Media.json",
//         "feedback": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMded05904ccb347238880ca9264e8fe1c/Feedback.json"
//       },
//       "to": "+18182008801",
//       "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMded05904ccb347238880ca9264e8fe1c.json"
//     },
//     {
//       "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
//       "api_version": "2010-04-01",
//       "body": "look mom I have media!",
//       "date_created": "Fri, 24 May 2019 17:44:46 +0000",
//       "date_sent": "Fri, 24 May 2019 17:44:49 +0000",
//       "date_updated": "Fri, 24 May 2019 17:44:49 +0000",
//       "direction": "inbound",
//       "error_code": 30004,
//       "error_message": "Message blocked",
//       "from": "+12019235161",
//       "messaging_service_sid": null,
//       "num_media": "3",
//       "num_segments": "1",
//       "price": "-0.00750",
//       "price_unit": "USD",
//       "sid": "MMc26223853f8c46b4ab7dfaa6abba0a26",
//       "status": "received",
//       "subresource_uris": {
//         "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26/Media.json",
//         "feedback": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26/Feedback.json"
//       },
//       "to": "+18182008801",
//       "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26.json"
//     }
//   ],
//   "start": 0,
//   "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0"
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

let end = json.int_of("end");
let first_page_uri = json.string_of("first_page_uri").unwrap_or_default();
let next_page_uri = json.string_of("next_page_uri").unwrap_or_default();
let page = json.int_of("page");
let page_size = json.int_of("page_size");
let previous_page_uri = json.string_of("previous_page_uri").unwrap_or_default();
let start = json.int_of("start");
let mut uri = json.string_of("uri").unwrap_or_default();
let mut i = 0;
let count_i = json.size_of_array("messages");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("messages[i].account_sid").unwrap_or_default();
    let _ = json.string_of("messages[i].api_version").unwrap_or_default();
    let _ = json.string_of("messages[i].body").unwrap_or_default();
    let _ = json.string_of("messages[i].date_created").unwrap_or_default();
    let _ = json.string_of("messages[i].date_sent").unwrap_or_default();
    let _ = json.string_of("messages[i].date_updated").unwrap_or_default();
    let _ = json.string_of("messages[i].direction").unwrap_or_default();
    let _ = json.string_of("messages[i].error_code").unwrap_or_default();
    let _ = json.string_of("messages[i].error_message").unwrap_or_default();
    let _ = json.string_of("messages[i].from").unwrap_or_default();
    let _ = json.string_of("messages[i].messaging_service_sid").unwrap_or_default();
    let _ = json.string_of("messages[i].num_media").unwrap_or_default();
    let _ = json.string_of("messages[i].num_segments").unwrap_or_default();
    let _ = json.string_of("messages[i].price").unwrap_or_default();
    let _ = json.string_of("messages[i].price_unit").unwrap_or_default();
    let _ = json.string_of("messages[i].sid").unwrap_or_default();
    let _ = json.string_of("messages[i].status").unwrap_or_default();
    let _ = json.string_of("messages[i].subresource_uris.media").unwrap_or_default();
    let _ = json.string_of("messages[i].subresource_uris.feedback").unwrap_or_default();
    let _ = json.string_of("messages[i].to").unwrap_or_default();
    uri = json.string_of("messages[i].uri").unwrap_or_default();
    i = i + 1;
}