Sample code for 30+ languages & platforms
Rust

Ecwid - Create Order

See more Ecwid Examples

Create a new order in an Ecwid store. This can be useful for storefronts with a custom checkout process or manually creating orders for sales made earlier.

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// Create and send the following HTTP request:

// Load the access token previously obtained in Ecwid Get Access Token
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/ecwid.json");

let sb_url = chilkat::StringBuilder::new();
let _ = sb_url.append("https://app.ecwid.com/api/v3/4870020/orders?token=");
let _ = sb_url.append(&json_token.string_of("access_token").unwrap_or_default());

// POST /api/v3/4870020/orders?token=1234567890qwqeertt HTTP/1.1
// Host: app.ecwid.com
// Content-Type: application/json;charset=utf-8
// Cache-Control: no-cache
// 
// {
//         "subtotal": 30,
//         "total": 40,
//         "email": "example@example.com",
//         "paymentMethod": "Phone order",
//         "tax": 0,
//         "paymentStatus": "PAID",
//         "customerTaxExempt": false,
//         "customerTaxId": "",
//         "customerTaxIdValid": false,
//         "reversedTaxApplied": false,
//         "fulfillmentStatus": "AWAITING_PROCESSING",
//         "createDate": "2015-09-20 19:59:43 +0000",
//         "items": [
//             {
//                 "price": 15,
//                 "weight": 0.32,
//                 "sku": "00004",
//                 "quantity": 2,
//                 "name": "Cherry"
//             }
//         ],
//         "billingPerson": {
//             "name": "Eugene K",
//             "companyName": "Hedgehog and Bucket",
//             "street": "My Street",
//             "city": "San Diego",
//             "countryCode": "US",
//             "postalCode": "90002",
//             "stateOrProvinceCode": "CA",
//             "phone": "123141321"
//         },
//         "shippingPerson": {
//             "name": "Eugene K",
//             "companyName": "Hedgehog and Bucket",
//             "street": "My Street",
//             "city": "San Diego",
//             "countryCode": "US",
//             "postalCode": "90002",
//             "stateOrProvinceCode": "CA",
//             "phone": "123141321"
//         },
//         "shippingOption": {
//             "shippingMethodName": "Fast Delivery",
//             "shippingRate": 10,
//             "isPickup": false,
//             "fulfilmentType": "DELIVERY"
//         },
//         "hidden": false,
//         "privateAdminNotes": "Must be delivered till Sunday.",
//         "acceptMarketing": false,
//         "disableAllCustomerNotifications": true,
//         "externalFulfillment": true,
//         "externalOrderId": "2",
//         "pricesIncludeTax": false  
//     }

let http = chilkat::Http::new();
http.set_request_header("Cache-Control", "no-cache");

let json = chilkat::JsonObject::new();
let _ = json.update_int("subtotal", 30);
let _ = json.update_int("total", 40);
let _ = json.update_string("email", "example@example.com");
let _ = json.update_string("paymentMethod", "Phone order");
let _ = json.update_int("tax", 0);
let _ = json.update_string("paymentStatus", "PAID");
let _ = json.update_bool("customerTaxExempt", false);
let _ = json.update_string("customerTaxId", "");
let _ = json.update_bool("customerTaxIdValid", false);
let _ = json.update_bool("reversedTaxApplied", false);
let _ = json.update_string("fulfillmentStatus", "AWAITING_PROCESSING");
let _ = json.update_string("createDate", "2015-09-20 19:59:43 +0000");
let _ = json.update_int("items[0].price", 15);
let _ = json.update_number("items[0].weight", "0.32");
let _ = json.update_string("items[0].sku", "00004");
let _ = json.update_int("items[0].quantity", 2);
let _ = json.update_string("items[0].name", "Cherry");
let _ = json.update_string("billingPerson.name", "Eugene K");
let _ = json.update_string("billingPerson.companyName", "Hedgehog and Bucket");
let _ = json.update_string("billingPerson.street", "My Street");
let _ = json.update_string("billingPerson.city", "San Diego");
let _ = json.update_string("billingPerson.countryCode", "US");
let _ = json.update_string("billingPerson.postalCode", "90002");
let _ = json.update_string("billingPerson.stateOrProvinceCode", "CA");
let _ = json.update_string("billingPerson.phone", "123141321");
let _ = json.update_string("shippingPerson.name", "Eugene K");
let _ = json.update_string("shippingPerson.companyName", "Hedgehog and Bucket");
let _ = json.update_string("shippingPerson.street", "My Street");
let _ = json.update_string("shippingPerson.city", "San Diego");
let _ = json.update_string("shippingPerson.countryCode", "US");
let _ = json.update_string("shippingPerson.postalCode", "90002");
let _ = json.update_string("shippingPerson.stateOrProvinceCode", "CA");
let _ = json.update_string("shippingPerson.phone", "123141321");
let _ = json.update_string("shippingOption.shippingMethodName", "Fast Delivery");
let _ = json.update_int("shippingOption.shippingRate", 10);
let _ = json.update_bool("shippingOption.isPickup", false);
let _ = json.update_string("shippingOption.fulfilmentType", "DELIVERY");
let _ = json.update_bool("hidden", false);
let _ = json.update_string("privateAdminNotes", "Must be delivered till Sunday.");
let _ = json.update_bool("acceptMarketing", false);
let _ = json.update_bool("disableAllCustomerNotifications", true);
let _ = json.update_bool("externalFulfillment", true);
let _ = json.update_string("externalOrderId", "2");
let _ = json.update_bool("pricesIncludeTax", false);

let url = sb_url.get_as_string().unwrap_or_default();
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());

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());

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "id": 20,
//   "orderid": "XJ12H"
// }

// 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 id = j_resp.int_of("id");
let orderid = j_resp.string_of("orderid").unwrap_or_default();