Rust
Rust
QuickBooks - Create an Account
See more QuickBooks Examples
Demonstrates how to send an JSON request to create a QuickBooks account.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First get our previously obtained OAuth2 access token.
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/qb-access-token.json").is_ok();
let rest = chilkat::Rest::new();
let b_auto_reconnect = true;
if rest.connect("sandbox-quickbooks.api.intuit.com", 443, true, b_auto_reconnect).is_err() {
println!("{}", rest.last_error_text());
return;
}
let sb_auth = chilkat::StringBuilder::new();
let _ = sb_auth.append("Bearer ");
let _ = sb_auth.append(&json_token.string_of("access_token").unwrap_or_default());
rest.set_authorization(&sb_auth.get_as_string().unwrap_or_default());
let json_request = chilkat::JsonObject::new();
let _ = json_request.append_string("AccountType", "Credit Card");
let _ = json_request.append_string("Name", "Banana Republic");
let request_body = json_request.emit().unwrap_or_default();
// "123146096291789" is the company ID.
let sb_path = chilkat::StringBuilder::new();
let _ = sb_path.append("/v3/company/123146096291789/account?minorversion=45");
let _ = rest.add_header("Content-Type", "application/json");
let _ = rest.add_header("Accept", "application/json");
rest.set_allow_header_folding(false);
let Ok(response_body) = rest.full_request_string("POST", &sb_path.get_as_string().unwrap_or_default(), &request_body) else {
println!("{}", rest.last_error_text());
return;
};
// We should expect a 200 response if successful.
if rest.response_status_code() != 200 {
println!("Request Header: ");
println!("{}", rest.last_request_header());
println!("----");
println!("Response StatusCode = {}", rest.response_status_code());
println!("Response StatusLine: {}", rest.response_status_text());
println!("Response Header:");
println!("{}", rest.response_header());
println!("{}", response_body);
return;
}
let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&response_body);
json_response.set_emit_compact(false);
println!("{}", json_response.emit().unwrap_or_default());
println!("Success.");
// A sample JSON response:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "Account": {
// "Name": "Banana Republic",
// "SubAccount": false,
// "FullyQualifiedName": "Banana Republic",
// "Active": true,
// "Classification": "Liability",
// "AccountType": "Credit Card",
// "AccountSubType": "CreditCard",
// "CurrentBalance": 0,
// "CurrentBalanceWithSubAccounts": 0,
// "CurrencyRef": {
// "value": "USD",
// "name": "United States Dollar"
// },
// "domain": "QBO",
// "sparse": false,
// "Id": "97",
// "SyncToken": "0",
// "MetaData": {
// "CreateTime": "2016-10-25T05:07:12-07:00",
// "LastUpdatedTime": "2016-10-25T05:07:12-07:00"
// }
// },
// "time": "2016-10-25T05:07:11.714-07:00"
// }