Rust
Rust
MYOB: Add a Category
See more MYOB Examples
Sends a POST to add a general ledger category.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 --request POST "https://api.myob.com/accountright/c06778dd-4371-4a83-975f-522df65d7574/GeneralLedger/Category" \
// --header "Authorization: Bearer ACCESS_TOKEN" \
// --header "x-myobapi-key: {{myob_api_key}}" \
// --header "x-myobapi-version: v2" \
// --header "Accept-Encoding: gzip,deflate" \
// --data "{
// \"DisplayID\" : \"CAT002\",
// \"Name\" : \"Victoria\",
// \"Description\" : \"Demo API Category Endpoint.\",
// \"IsActive\" : true
// }"
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "DisplayID": "CAT002",
// "Name": "Victoria",
// "Description": "Demo API Category Endpoint.",
// "IsActive": true
// }
let json = chilkat::JsonObject::new();
let _ = json.update_string("DisplayID", "CAT002");
let _ = json.update_string("Name", "Victoria");
let _ = json.update_string("Description", "Demo API Category Endpoint.");
let _ = json.update_bool("IsActive", true);
http.set_request_header("Authorization", "Bearer ACCESS_TOKEN");
http.set_request_header("x-myobapi-key", "{{myob_api_key}}");
http.set_request_header("Accept-Encoding", "gzip,deflate");
http.set_request_header("x-myobapi-version", "v2");
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://api.myob.com/accountright/c06778dd-4371-4a83-975f-522df65d7574/GeneralLedger/Category", &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code != 200 {
println!("Response Header:");
println!("{}", resp.header());
println!("Response Body:");
println!("{}", resp.body_str());
println!("Failed.");
return;
}
println!("Success.");