PowerBuilder
PowerBuilder
Shippo Create the Shipment, Get Rates, and Purchase Label
See more Shippo Examples
Demonstrates how retrieve rates and create labels for international shipments.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_Template
string ls_Length
string ls_Width
string ls_Height
string ls_Distance_unit
string ls_Weight
string ls_Mass_unit
string ls_Value_amount
string ls_Value_currency
integer li_Test
integer j
integer li_Count_j
integer li_IntVal
string ls_Object_created
string ls_Object_updated
string ls_Object_id
string ls_Object_owner
string ls_Status
string ls_Address_fromObject_id
integer li_Address_fromIs_complete
string ls_Address_fromCompany
string ls_Address_fromStreet_no
string ls_Address_fromName
string ls_Address_fromStreet1
string ls_Address_fromStreet2
string ls_Address_fromCity
string ls_Address_fromState
string ls_Address_fromZip
string ls_Address_fromCountry
string ls_Address_fromPhone
string ls_Address_fromEmail
string ls_Address_fromIs_residential
string ls_Address_toObject_id
integer li_Address_toIs_complete
string ls_Address_toName
string ls_Address_toStreet1
string ls_Address_toCity
string ls_Address_toState
string ls_Address_toZip
string ls_Address_toCountry
string ls_Address_toPhone
string ls_Address_toEmail
integer li_Address_toIs_residential
string ls_Address_return
string ls_Shipment_date
string ls_ExtraInsuranceCurrency
string ls_ExtraInsuranceAmount
string ls_ExtraReference_1
string ls_ExtraReference_2
string ls_Customs_declaration
string ls_Metadata
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
// Implements the following CURL command:
// curl https://api.goshippo.com/customs/declarations/ \
// -H "Authorization: ShippoToken <API_TOKEN>" \
// -H "Content-Type: application/json" \
// -d '{
// "contents_type": "MERCHANDISE",
// "non_delivery_option": "RETURN",
// "certify": true,
// "certify_signer": "Simon Kreuz",
// "incoterm": "DDU",
// "items": [{
// "description": "T-shirt",
// "quantity": 20,
// "net_weight": "5",
// "mass_unit": "lb",
// "value_amount": "200",
// "value_currency": "USD",
// "tariff_number": "",
// "origin_country": "US"
// }]
// }'
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "contents_type": "MERCHANDISE",
// "non_delivery_option": "RETURN",
// "certify": true,
// "certify_signer": "Simon Kreuz",
// "incoterm": "DDU",
// "items": [
// {
// "description": "T-shirt",
// "quantity": 20,
// "net_weight": "5",
// "mass_unit": "lb",
// "value_amount": "200",
// "value_currency": "USD",
// "tariff_number": "",
// "origin_country": "US"
// }
// ]
// }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("contents_type","MERCHANDISE")
loo_Json.UpdateString("non_delivery_option","RETURN")
loo_Json.UpdateBool("certify",1)
loo_Json.UpdateString("certify_signer","Simon Kreuz")
loo_Json.UpdateString("incoterm","DDU")
loo_Json.UpdateString("items[0].description","T-shirt")
loo_Json.UpdateInt("items[0].quantity",20)
loo_Json.UpdateString("items[0].net_weight","5")
loo_Json.UpdateString("items[0].mass_unit","lb")
loo_Json.UpdateString("items[0].value_amount","200")
loo_Json.UpdateString("items[0].value_currency","USD")
loo_Json.UpdateString("items[0].tariff_number","")
loo_Json.UpdateString("items[0].origin_country","US")
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/customs/declarations/",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_created": "2014-07-17T00:04:06.163Z",
// "object_updated": "2014-07-17T00:04:06.163Z",
// "object_id": "89436997a794439ab47999701e60392e",
// "object_owner": "shippotle@goshippo.com",
// "status": "SUCCESS",
// "address_from": {
// "object_id": "0943ae4e373e4120a99c337e496dcce8",
// "validation_results": {},
// "is_complete": true,
// "company": "",
// "street_no": "",
// "name": "Mr. Hippo",
// "street1": "215 Clayton St.",
// "street2": "",
// "city": "San Francisco",
// "state": "CA",
// "zip": "94117",
// "country": "US",
// "phone": "+15553419393",
// "email": "support@goshippo.com",
// "is_residential": null
// },
// "address_to": {
// "object_id": "4c7185d353764d0985a6a7825aed8ffb",
// "validation_results": {},
// "is_complete": true,
// "name": "Mrs. Hippo",
// "street1": "200 University Ave W",
// "city": "Waterloo",
// "state": "ON",
// "zip": "N2L 3G1",
// "country": "CA",
// "phone": "+1 555 341 9393",
// "email": "support@goshippo.com",
// "is_residential": false
// },
// "address_return": null,
// "parcels": [
// {
// "object_id": "ec952343dd4843c39b42aca620471fd5",
// "object_created": "2013-12-01T06:24:21.121Z",
// "object_updated": "2013-12-01T06:24:21.121Z",
// "object_owner": "shippotle@goshippo.com",
// "template": null,
// "length": "5",
// "width": "5",
// "height": "5",
// "distance_unit": "in",
// "weight": "2",
// "mass_unit": "lb",
// "value_amount": null,
// "value_currency": null,
// "metadata": "",
// "line_items": [
// ],
// "test": true
// }
// ],
// "shipment_date": "2013-12-03T12:00:00Z",
// "extra": {
// "insurance": {
// "currency": "",
// "amount": ""
// },
// "reference_1": "",
// "reference_2": ""
// },
// "customs_declaration": "b741b99f95e841639b54272834bc478c",
// "rates": [
// {
// "object_created": "2014-07-17T00:04:06.263Z",
// "object_id": "545ab0a1a6ea4c9f9adb2512a57d6d8b",
// "object_owner": "shippotle@goshippo.com",
// "shipment": "89436997a794439ab47999701e60392e",
// "attributes": [
// ],
// "amount": "5.50",
// "currency": "USD",
// "amount_local": "5.50",
// "currency_local": "USD",
// "provider": "USPS",
// "provider_image_75": "https://cdn2.goshippo.com/providers/75/USPS.png",
// "provider_image_200": "https://cdn2.goshippo.com/providers/200/USPS.png",
// "servicelevel": {
// "name": "Priority Mail",
// "token": "usps_priority",
// "terms": ""
// },
// "days": 2,
// "arrives_by": null,
// "duration_terms": "Delivery in 1 to 3 business days.",
// "messages": [
// ],
// "carrier_account": "078870331023437cb917f5187429b093",
// "test": false,
// "zone": 1
// },
// ...
// ],
// "carrier_accounts": [
// ],
// "messages": [
// ],
// "metadata": "Customer ID 123456"
// }
// 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_created = loo_JResp.StringOf("object_created")
ls_Object_updated = loo_JResp.StringOf("object_updated")
ls_Object_id = loo_JResp.StringOf("object_id")
ls_Object_owner = loo_JResp.StringOf("object_owner")
ls_Status = loo_JResp.StringOf("status")
ls_Address_fromObject_id = loo_JResp.StringOf("address_from.object_id")
li_Address_fromIs_complete = loo_JResp.BoolOf("address_from.is_complete")
ls_Address_fromCompany = loo_JResp.StringOf("address_from.company")
ls_Address_fromStreet_no = loo_JResp.StringOf("address_from.street_no")
ls_Address_fromName = loo_JResp.StringOf("address_from.name")
ls_Address_fromStreet1 = loo_JResp.StringOf("address_from.street1")
ls_Address_fromStreet2 = loo_JResp.StringOf("address_from.street2")
ls_Address_fromCity = loo_JResp.StringOf("address_from.city")
ls_Address_fromState = loo_JResp.StringOf("address_from.state")
ls_Address_fromZip = loo_JResp.StringOf("address_from.zip")
ls_Address_fromCountry = loo_JResp.StringOf("address_from.country")
ls_Address_fromPhone = loo_JResp.StringOf("address_from.phone")
ls_Address_fromEmail = loo_JResp.StringOf("address_from.email")
ls_Address_fromIs_residential = loo_JResp.StringOf("address_from.is_residential")
ls_Address_toObject_id = loo_JResp.StringOf("address_to.object_id")
li_Address_toIs_complete = loo_JResp.BoolOf("address_to.is_complete")
ls_Address_toName = loo_JResp.StringOf("address_to.name")
ls_Address_toStreet1 = loo_JResp.StringOf("address_to.street1")
ls_Address_toCity = loo_JResp.StringOf("address_to.city")
ls_Address_toState = loo_JResp.StringOf("address_to.state")
ls_Address_toZip = loo_JResp.StringOf("address_to.zip")
ls_Address_toCountry = loo_JResp.StringOf("address_to.country")
ls_Address_toPhone = loo_JResp.StringOf("address_to.phone")
ls_Address_toEmail = loo_JResp.StringOf("address_to.email")
li_Address_toIs_residential = loo_JResp.BoolOf("address_to.is_residential")
ls_Address_return = loo_JResp.StringOf("address_return")
ls_Shipment_date = loo_JResp.StringOf("shipment_date")
ls_ExtraInsuranceCurrency = loo_JResp.StringOf("extra.insurance.currency")
ls_ExtraInsuranceAmount = loo_JResp.StringOf("extra.insurance.amount")
ls_ExtraReference_1 = loo_JResp.StringOf("extra.reference_1")
ls_ExtraReference_2 = loo_JResp.StringOf("extra.reference_2")
ls_Customs_declaration = loo_JResp.StringOf("customs_declaration")
ls_Metadata = loo_JResp.StringOf("metadata")
i = 0
li_Count_i = loo_JResp.SizeOfArray("parcels")
do while i < li_Count_i
loo_JResp.I = i
ls_Object_id = loo_JResp.StringOf("parcels[i].object_id")
ls_Object_created = loo_JResp.StringOf("parcels[i].object_created")
ls_Object_updated = loo_JResp.StringOf("parcels[i].object_updated")
ls_Object_owner = loo_JResp.StringOf("parcels[i].object_owner")
ls_Template = loo_JResp.StringOf("parcels[i].template")
ls_Length = loo_JResp.StringOf("parcels[i].length")
ls_Width = loo_JResp.StringOf("parcels[i].width")
ls_Height = loo_JResp.StringOf("parcels[i].height")
ls_Distance_unit = loo_JResp.StringOf("parcels[i].distance_unit")
ls_Weight = loo_JResp.StringOf("parcels[i].weight")
ls_Mass_unit = loo_JResp.StringOf("parcels[i].mass_unit")
ls_Value_amount = loo_JResp.StringOf("parcels[i].value_amount")
ls_Value_currency = loo_JResp.StringOf("parcels[i].value_currency")
ls_Metadata = loo_JResp.StringOf("parcels[i].metadata")
li_Test = loo_JResp.BoolOf("parcels[i].test")
j = 0
li_Count_j = loo_JResp.SizeOfArray("parcels[i].line_items")
do while j < li_Count_j
loo_JResp.J = j
j = j + 1
loop
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("rates")
do while i < li_Count_i
loo_JResp.I = i
li_IntVal = loo_JResp.IntOf("rates[i]")
j = 0
li_Count_j = loo_JResp.SizeOfArray("rates[i].attributes")
do while j < li_Count_j
loo_JResp.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JResp.SizeOfArray("rates[i].messages")
do while j < li_Count_j
loo_JResp.J = j
j = j + 1
loop
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("carrier_accounts")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("messages")
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