Sample code for 30+ languages & platforms
Xbase++

Shippo Create an Order

See more Shippo Examples

Demonstrates how to create an order with all the information about your order by sending a POST request to the orders endpoint.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

//  Implements the following CURL command:

//  curl https://api.goshippo.com/orders/ \
//      -H "Authorization: ShippoToken <API_Token>" \
//      -H "Content-Type: application/json"  \
//      -d '{
//              "to_address": {
//                  "city": "San Francisco",
//                  "company": "Shippo",
//                  "country": "US",
//                  "email": "shippotle@goshippo.com",
//                  "name": "Mr Hippo",
//                  "phone": "15553419393",
//                  "state": "CA",
//                  "street1": "215 Clayton St.",
//                  "zip": "94117"
//              },
//              "line_items": [
//                  {
//                      "quantity": 1,
//                      "sku": "HM-123",
//                      "title": "Hippo Magazines",
//                      "total_price": "12.10",
//                      "currency": "USD",
//                      "weight": "0.40",
//                      "weight_unit": "lb"
//                  }
//              ],
//              "placed_at": "2016-09-23T01:28:12Z",
//              "order_number": "#1068",
//              "order_status": "PAID",
//              "shipping_cost": "12.83",
//              "shipping_cost_currency": "USD",
//              "shipping_method": "USPS First Class Package",
//              "subtotal_price": "12.10",
//              "total_price": "24.93",
//              "total_tax": "0.00",
//              "currency": "USD",
//              "weight": "0.40",
//              "weight_unit": "lb"
//          }'

//  Use this online tool to generate code from sample JSON:
//  Generate Code to Create JSON

//  The following JSON is sent in the request body.

//  {
//    "to_address": {
//      "city": "San Francisco",
//      "company": "Shippo",
//      "country": "US",
//      "email": "shippotle@goshippo.com",
//      "name": "Mr Hippo",
//      "phone": "15553419393",
//      "state": "CA",
//      "street1": "215 Clayton St.",
//      "zip": "94117"
//    },
//    "line_items": [
//      {
//        "quantity": 1,
//        "sku": "HM-123",
//        "title": "Hippo Magazines",
//        "total_price": "12.10",
//        "currency": "USD",
//        "weight": "0.40",
//        "weight_unit": "lb"
//      }
//    ],
//    "placed_at": "2016-09-23T01:28:12Z",
//    "order_number": "#1068",
//    "order_status": "PAID",
//    "shipping_cost": "12.83",
//    "shipping_cost_currency": "USD",
//    "shipping_method": "USPS First Class Package",
//    "subtotal_price": "12.10",
//    "total_price": "24.93",
//    "total_tax": "0.00",
//    "currency": "USD",
//    "weight": "0.40",
//    "weight_unit": "lb"
//  }

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("to_address.city", "San Francisco")
oJson:UpdateString("to_address.company", "Shippo")
oJson:UpdateString("to_address.country", "US")
oJson:UpdateString("to_address.email", "shippotle@goshippo.com")
oJson:UpdateString("to_address.name", "Mr Hippo")
oJson:UpdateString("to_address.phone", "15553419393")
oJson:UpdateString("to_address.state", "CA")
oJson:UpdateString("to_address.street1", "215 Clayton St.")
oJson:UpdateString("to_address.zip", "94117")
oJson:UpdateInt("line_items[0].quantity", 1)
oJson:UpdateString("line_items[0].sku", "HM-123")
oJson:UpdateString("line_items[0].title", "Hippo Magazines")
oJson:UpdateString("line_items[0].total_price", "12.10")
oJson:UpdateString("line_items[0].currency", "USD")
oJson:UpdateString("line_items[0].weight", "0.40")
oJson:UpdateString("line_items[0].weight_unit", "lb")
oJson:UpdateString("placed_at", "2016-09-23T01:28:12Z")
oJson:UpdateString("order_number", "#1068")
oJson:UpdateString("order_status", "PAID")
oJson:UpdateString("shipping_cost", "12.83")
oJson:UpdateString("shipping_cost_currency", "USD")
oJson:UpdateString("shipping_method", "USPS First Class Package")
oJson:UpdateString("subtotal_price", "12.10")
oJson:UpdateString("total_price", "24.93")
oJson:UpdateString("total_tax", "0.00")
oJson:UpdateString("currency", "USD")
oJson:UpdateString("weight", "0.40")
oJson:UpdateString("weight_unit", "lb")

oHttp:SetRequestHeader("Authorization", "ShippoToken <API_Token>")
oHttp:SetRequestHeader("Content-Type", "application/json")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://api.goshippo.com/orders/", oJson, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

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

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

nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oResp:Header
    ? "Failed."
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    RETURN
ENDIF

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

//  {}

//  Sample code for parsing the JSON response...
//  Use the following online tool to generate parsing code from sample JSON:
//  Generate Parsing Code from JSON

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