Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
long li_RespStatusCode

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

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

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

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://api.goshippo.com/orders/",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

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



destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp