PowerBuilder
PowerBuilder
Shippo Create a Batch
See more Shippo Examples
Demonstrates how to create and purchase up to 10,000 shipments in a single API request.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Object_id
string ls_Object_owner
string ls_Status
string ls_Object_created
string ls_Object_updated
string ls_Metadata
string ls_Default_carrier_account
string ls_Default_servicelevel_token
string ls_Label_filetype
string ls_Batch_shipmentsNext
string ls_Batch_shipmentsPrevious
integer li_Object_resultsPurchase_succeeded
integer li_Object_resultsPurchase_failed
integer li_Object_resultsCreation_failed
integer li_Object_resultsCreation_succeeded
integer i
integer li_Count_i
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
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "default_carrier_account": "078870331023437cb917f5187429b093",
// "default_servicelevel_token": "usps_priority",
// "label_filetype": "PDF_4x6",
// "metadata": "BATCH #170",
// "batch_shipments": [
// {
// "shipment": {
// "address_from": {
// "name": "Mr Hippo",
// "street1": "965 Mission St",
// "street2": "Ste 201",
// "city": "San Francisco",
// "state": "CA",
// "zip": "94103",
// "country": "US",
// "phone": "4151234567",
// "email": "mrhippo@goshippo.com"
// },
// "address_to": {
// "name": "Mrs Hippo",
// "company": "",
// "street1": "Broadway 1",
// "street2": "",
// "city": "New York",
// "state": "NY",
// "zip": "10007",
// "country": "US",
// "phone": "4151234567",
// "email": "mrshippo@goshippo.com"
// },
// "parcels": [
// {
// "length": "5",
// "width": "5",
// "height": "5",
// "distance_unit": "in",
// "weight": "2",
// "mass_unit": "oz"
// }
// ]
// }
// },
// {
// "shipment": {
// "address_from": {
// "name": "Mr Hippo",
// "street1": "1092 Indian Summer Ct",
// "city": "San Jose",
// "state": "CA",
// "zip": "95122",
// "country": "US",
// "phone": "4151234567",
// "email": "mrhippo@goshippo.com"
// },
// "address_to": {
// "name": "Mrs Hippo",
// "company": "",
// "street1": "Broadway 1",
// "street2": "",
// "city": "New York",
// "state": "NY",
// "zip": "10007",
// "country": "US",
// "phone": "4151234567",
// "email": "mrshippo@goshippo.com"
// },
// "parcels": [
// {
// "length": "5",
// "width": "5",
// "height": "5",
// "distance_unit": "in",
// "weight": "20",
// "mass_unit": "lb"
// }
// ]
// },
// "carrier_account": "a4391cd4ab974f478f55dc08b5c8e3b3",
// "servicelevel_token": "fedex_2_day"
// }
// ]
// }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("default_carrier_account","078870331023437cb917f5187429b093")
loo_Json.UpdateString("default_servicelevel_token","usps_priority")
loo_Json.UpdateString("label_filetype","PDF_4x6")
loo_Json.UpdateString("metadata","BATCH #170")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.name","Mr Hippo")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.street1","965 Mission St")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.street2","Ste 201")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.city","San Francisco")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.state","CA")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.zip","94103")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.country","US")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.phone","4151234567")
loo_Json.UpdateString("batch_shipments[0].shipment.address_from.email","mrhippo@goshippo.com")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.name","Mrs Hippo")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.company","")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.street1","Broadway 1")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.street2","")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.city","New York")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.state","NY")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.zip","10007")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.country","US")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.phone","4151234567")
loo_Json.UpdateString("batch_shipments[0].shipment.address_to.email","mrshippo@goshippo.com")
loo_Json.UpdateString("batch_shipments[0].shipment.parcels[0].length","5")
loo_Json.UpdateString("batch_shipments[0].shipment.parcels[0].width","5")
loo_Json.UpdateString("batch_shipments[0].shipment.parcels[0].height","5")
loo_Json.UpdateString("batch_shipments[0].shipment.parcels[0].distance_unit","in")
loo_Json.UpdateString("batch_shipments[0].shipment.parcels[0].weight","2")
loo_Json.UpdateString("batch_shipments[0].shipment.parcels[0].mass_unit","oz")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.name","Mr Hippo")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.street1","1092 Indian Summer Ct")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.city","San Jose")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.state","CA")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.zip","95122")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.country","US")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.phone","4151234567")
loo_Json.UpdateString("batch_shipments[1].shipment.address_from.email","mrhippo@goshippo.com")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.name","Mrs Hippo")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.company","")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.street1","Broadway 1")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.street2","")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.city","New York")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.state","NY")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.zip","10007")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.country","US")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.phone","4151234567")
loo_Json.UpdateString("batch_shipments[1].shipment.address_to.email","mrshippo@goshippo.com")
loo_Json.UpdateString("batch_shipments[1].shipment.parcels[0].length","5")
loo_Json.UpdateString("batch_shipments[1].shipment.parcels[0].width","5")
loo_Json.UpdateString("batch_shipments[1].shipment.parcels[0].height","5")
loo_Json.UpdateString("batch_shipments[1].shipment.parcels[0].distance_unit","in")
loo_Json.UpdateString("batch_shipments[1].shipment.parcels[0].weight","20")
loo_Json.UpdateString("batch_shipments[1].shipment.parcels[0].mass_unit","lb")
loo_Json.UpdateString("batch_shipments[1].carrier_account","a4391cd4ab974f478f55dc08b5c8e3b3")
loo_Json.UpdateString("batch_shipments[1].servicelevel_token","fedex_2_day")
loo_Http.SetRequestHeader("Authorization","ShippoToken shippo_test_3af5d574e2f845d30efcaf9b2f47d9c2aef4807a")
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/batches/",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)
// {
// "object_id": "a015eb693cca465dbb6523ce6d2e3c65",
// "object_owner": "admin",
// "status": "VALIDATING",
// "object_created": "2016-09-12T15:25:43.465Z",
// "object_updated": "2016-09-12T15:25:43.465Z",
// "metadata": "BATCH #170",
// "default_carrier_account": "078870331023437cb917f5187429b093",
// "default_servicelevel_token": "usps_priority",
// "label_filetype": "PDF_4x6",
// "batch_shipments": {
// "next": null,
// "previous": null,
// "results": [
// ]
// },
// "object_results": {
// "purchase_succeeded": 0,
// "purchase_failed": 0,
// "creation_failed": 0,
// "creation_succeeded": 0
// },
// "label_url": [
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
ls_Object_id = loo_JResp.StringOf("object_id")
ls_Object_owner = loo_JResp.StringOf("object_owner")
ls_Status = loo_JResp.StringOf("status")
ls_Object_created = loo_JResp.StringOf("object_created")
ls_Object_updated = loo_JResp.StringOf("object_updated")
ls_Metadata = loo_JResp.StringOf("metadata")
ls_Default_carrier_account = loo_JResp.StringOf("default_carrier_account")
ls_Default_servicelevel_token = loo_JResp.StringOf("default_servicelevel_token")
ls_Label_filetype = loo_JResp.StringOf("label_filetype")
ls_Batch_shipmentsNext = loo_JResp.StringOf("batch_shipments.next")
ls_Batch_shipmentsPrevious = loo_JResp.StringOf("batch_shipments.previous")
li_Object_resultsPurchase_succeeded = loo_JResp.IntOf("object_results.purchase_succeeded")
li_Object_resultsPurchase_failed = loo_JResp.IntOf("object_results.purchase_failed")
li_Object_resultsCreation_failed = loo_JResp.IntOf("object_results.creation_failed")
li_Object_resultsCreation_succeeded = loo_JResp.IntOf("object_results.creation_succeeded")
i = 0
li_Count_i = loo_JResp.SizeOfArray("batch_shipments.results")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("label_url")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp