Rust
Rust
Faire - Get All Products
See more Faire Examples
Retrieves a list of products, ordered ascending by updated_at. By default, it only returns non-deleted products.Chilkat Rust Downloads
// 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 -H "X-FAIRE-ACCESS-TOKEN: <access_token>" -d "limit=50" -d "page=1" https://www.faire.com/api/v1/products
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
let query_params = chilkat::JsonObject::new();
let _ = query_params.update_int("limit", 50);
let _ = query_params.update_int("page", 1);
http.set_request_header("X-FAIRE-ACCESS-TOKEN", "<access_token>");
let resp = chilkat::HttpResponse::new();
if http.http_params("GET", "https://www.faire.com/api/v1/products", &query_params, &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "page": 1,
// "limit": 50,
// "products": [
// {
// "id": "p_123",
// "brand_id": "b_abc",
// "short_description": "Our candles smell fantastic. Want to know how good? Read our description!",
// "description": "Glad you decided to read our description! We have significantly more characters to describe to you just how good our candles smell.",
// "wholesale_price_cents": 500,
// "retail_price_cents": 1000,
// "sale_state": "FOR_SALE",
// "active": true,
// "deleted": false,
// "name": "Faire's fantastic candle",
// "unit_multiplier": 8,
// "taxonomy_type": {
// "id": "tt_23nl3bzl00",
// "name": "Votive Candle"
// },
// "options": [
// ],
// "created_at": "20190314T000915.000Z",
// "updated_at": "20190315T000915.000Z"
// }
// ]
// }
// 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 mut j: i32 = 0;
let mut count_j: i32 = 0;
let page = j_resp.int_of("page");
let limit = j_resp.int_of("limit");
let mut i = 0;
let count_i = j_resp.size_of_array("products");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("products[i].id").unwrap_or_default();
let _ = j_resp.string_of("products[i].brand_id").unwrap_or_default();
let _ = j_resp.string_of("products[i].short_description").unwrap_or_default();
let _ = j_resp.string_of("products[i].description").unwrap_or_default();
let _ = j_resp.int_of("products[i].wholesale_price_cents");
let _ = j_resp.int_of("products[i].retail_price_cents");
let _ = j_resp.string_of("products[i].sale_state").unwrap_or_default();
let _ = j_resp.bool_of("products[i].active");
let _ = j_resp.bool_of("products[i].deleted");
let _ = j_resp.string_of("products[i].name").unwrap_or_default();
let _ = j_resp.int_of("products[i].unit_multiplier");
let _ = j_resp.string_of("products[i].taxonomy_type.id").unwrap_or_default();
let _ = j_resp.string_of("products[i].taxonomy_type.name").unwrap_or_default();
let _ = j_resp.string_of("products[i].created_at").unwrap_or_default();
let _ = j_resp.string_of("products[i].updated_at").unwrap_or_default();
j = 0;
count_j = j_resp.size_of_array("products[i].options");
while j < count_j {
j_resp.set_j(j);
j = j + 1;
}
i = i + 1;
}