Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJsonToken
LOCAL oSbUrl
LOCAL oHttp
LOCAL oJson
LOCAL cUrl
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nId
LOCAL cOrderid

nSuccess := 0

//  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
oJsonToken := CreateObject("Chilkat.JsonObject")
oJsonToken:LoadFile("qa_data/tokens/ecwid.json")

oSbUrl := CreateObject("Chilkat.StringBuilder")
oSbUrl:Append("https://app.ecwid.com/api/v3/4870020/orders?token=")
oSbUrl:Append(oJsonToken:StringOf("access_token"))

//  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  
//      }

oHttp := CreateObject("Chilkat.Http")
oHttp:SetRequestHeader("Cache-Control", "no-cache")

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

cUrl := oSbUrl:GetAsString()
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", cUrl, oJson, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oJsonToken:destroy()
    oSbUrl:destroy()
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Response status code = " + Str(oResp:StatusCode)

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

//  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

nId := oJResp:IntOf("id")
cOrderid := oJResp:StringOf("orderid")

oJsonToken:destroy()
oSbUrl:destroy()
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()