Rust
Rust
Akeneo: Create New Family
See more HTTP Misc Examples
Demonstrates how to create a new family.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Use your previously obtained access token.
// See Get Akeneo Access Token
http.set_auth_token("access_token");
// Build the following JSON to be sent in the request body:
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
// {
// "code": "caps",
// "attributes": [
// "sku",
// "name",
// "description",
// "price",
// "color",
// "picture"
// ],
// "attribute_as_label": "name",
// "attribute_as_image": "picture",
// "attribute_requirements": {
// "ecommerce": [
// "sku",
// "name",
// "description",
// "price",
// "color"
// ],
// "tablet": [
// "sku",
// "name",
// "description",
// "price"
// ]
// },
// "labels": {
// "en_US": "Caps",
// "fr_FR": "Casquettes"
// }
// }
//
let json = chilkat::JsonObject::new();
let _ = json.update_string("code", "caps");
let _ = json.update_string("attributes[0]", "sku");
let _ = json.update_string("attributes[1]", "name");
let _ = json.update_string("attributes[2]", "description");
let _ = json.update_string("attributes[3]", "price");
let _ = json.update_string("attributes[4]", "color");
let _ = json.update_string("attributes[5]", "picture");
let _ = json.update_string("attribute_as_label", "name");
let _ = json.update_string("attribute_as_image", "picture");
let _ = json.update_string("attribute_requirements.ecommerce[0]", "sku");
let _ = json.update_string("attribute_requirements.ecommerce[1]", "name");
let _ = json.update_string("attribute_requirements.ecommerce[2]", "description");
let _ = json.update_string("attribute_requirements.ecommerce[3]", "price");
let _ = json.update_string("attribute_requirements.ecommerce[4]", "color");
let _ = json.update_string("attribute_requirements.tablet[0]", "sku");
let _ = json.update_string("attribute_requirements.tablet[1]", "name");
let _ = json.update_string("attribute_requirements.tablet[2]", "description");
let _ = json.update_string("attribute_requirements.tablet[3]", "price");
let _ = json.update_string("labels.en_US", "Caps");
let _ = json.update_string("labels.fr_FR", "Casquettes");
json.set_emit_compact(false);
// Show the JSON to be sent..
println!("{}", json.emit().unwrap_or_default());
let url = "http://pim.my-akeneo-site.com/api/rest/v1/families".to_string();
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", &url, &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
println!("Response Status Code: {}", resp.status_code());
println!("Response Body: ");
println!("{}", resp.body_str());