Sample code for 30+ languages & platforms
Rust

Akeneo: Create New Attribute

See more HTTP Misc Examples

Demonstrates how to create a new attribute.

Chilkat Rust Downloads

Rust

// 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": "release_date",
//   "type": "pim_catalog_date",
//   "group": "marketing",
//   "unique": false,
//   "useable_as_grid_filter": true,
//   "allowed_extensions": [],
//   "metric_family": null,
//   "default_metric_unit": null,
//   "reference_data_name": null,
//   "available_locales": [],
//   "max_characters": null,
//   "validation_rule": null,
//   "validation_regexp": null,
//   "wysiwyg_enabled": null,
//   "number_min": null,
//   "number_max": null,
//   "decimals_allowed": null,
//   "negative_allowed": null,
//   "date_min": "2017-06-28T08:00:00",
//   "date_max": "2017-08-08T22:00:00",
//   "max_file_size": null,
//   "minimum_input_length": null,
//   "sort_order": 1,
//   "localizable": false,
//   "scopable": false,
//   "labels": {
//     "en_US": "Sale date",
//     "fr_FR": "Date des soldes"
//   }
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("code", "release_date");
let _ = json.update_string("type", "pim_catalog_date");
let _ = json.update_string("group", "marketing");
let _ = json.update_bool("unique", false);
let _ = json.update_bool("useable_as_grid_filter", true);
let _ = json.update_new_array("allowed_extensions");
let _ = json.update_null("metric_family");
let _ = json.update_null("default_metric_unit");
let _ = json.update_null("reference_data_name");
let _ = json.update_new_array("available_locales");
let _ = json.update_null("max_characters");
let _ = json.update_null("validation_rule");
let _ = json.update_null("validation_regexp");
let _ = json.update_null("wysiwyg_enabled");
let _ = json.update_null("number_min");
let _ = json.update_null("number_max");
let _ = json.update_null("decimals_allowed");
let _ = json.update_null("negative_allowed");
let _ = json.update_string("date_min", "2017-06-28T08:00:00");
let _ = json.update_string("date_max", "2017-08-08T22:00:00");
let _ = json.update_null("max_file_size");
let _ = json.update_null("minimum_input_length");
let _ = json.update_number("sort_order", "1");
let _ = json.update_bool("localizable", false);
let _ = json.update_bool("scopable", false);
let _ = json.update_string("labels.en_US", "Sale date");
let _ = json.update_string("labels.fr_FR", "Date des soldes");

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/attributes".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());