Sample code for 30+ languages & platforms
Xbase++

Shippo Create Shipment Object

See more Shippo Examples

Create a Shipment object to retrieve rates. It represents a request to ship a given package from the sender to the recipient address.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cObject_state
LOCAL cTemplate
LOCAL cLength
LOCAL cWidth
LOCAL cHeight
LOCAL cDistance_unit
LOCAL cWeight
LOCAL cMass_unit
LOCAL cValue_amount
LOCAL cValue_currency
LOCAL j
LOCAL nCount_j
LOCAL cShipment
LOCAL cAmount
LOCAL cCurrency
LOCAL cAmount_local
LOCAL cCurrency_local
LOCAL cProvider
LOCAL cProvider_image_75
LOCAL cProvider_image_200
LOCAL cServicelevelName
LOCAL cServicelevelToken
LOCAL cServicelevelTerms
LOCAL nEstimated_days
LOCAL cArrives_by
LOCAL cDuration_terms
LOCAL cCarrier_account
LOCAL cZone
LOCAL cStrVal
LOCAL cSource
LOCAL cCode
LOCAL cText
LOCAL cObject_created
LOCAL cObject_updated
LOCAL cObject_id
LOCAL cObject_owner
LOCAL cStatus
LOCAL cAddress_fromObject_id
LOCAL nAddress_fromIs_complete
LOCAL cAddress_fromName
LOCAL cAddress_fromCompany
LOCAL cAddress_fromStreet_no
LOCAL cAddress_fromStreet1
LOCAL cAddress_fromStreet2
LOCAL cAddress_fromStreet3
LOCAL cAddress_fromCity
LOCAL cAddress_fromState
LOCAL cAddress_fromZip
LOCAL cAddress_fromCountry
LOCAL cAddress_fromPhone
LOCAL cAddress_fromEmail
LOCAL cAddress_fromIs_residential
LOCAL nAddress_fromTest
LOCAL cAddress_toObject_id
LOCAL nAddress_toIs_complete
LOCAL cAddress_toName
LOCAL cAddress_toCompany
LOCAL cAddress_toStreet_no
LOCAL cAddress_toStreet1
LOCAL cAddress_toStreet2
LOCAL cAddress_toStreet3
LOCAL cAddress_toCity
LOCAL cAddress_toState
LOCAL cAddress_toZip
LOCAL cAddress_toCountry
LOCAL cAddress_toPhone
LOCAL cAddress_toEmail
LOCAL cAddress_toIs_residential
LOCAL nAddress_toTest
LOCAL cShipment_date
LOCAL cAddress_returnObject_id
LOCAL nAddress_returnIs_complete
LOCAL cAddress_returnName
LOCAL cAddress_returnCompany
LOCAL cAddress_returnStreet_no
LOCAL cAddress_returnStreet1
LOCAL cAddress_returnStreet2
LOCAL cAddress_returnStreet3
LOCAL cAddress_returnCity
LOCAL cAddress_returnState
LOCAL cAddress_returnZip
LOCAL cAddress_returnCountry
LOCAL cAddress_returnPhone
LOCAL cAddress_returnEmail
LOCAL cAddress_returnIs_residential
LOCAL nAddress_returnTest
LOCAL cAlternate_address_to
LOCAL cCustoms_declaration
LOCAL cMetadata
LOCAL nTest
LOCAL cOrder
LOCAL i
LOCAL nCount_i

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/shipments/  \
//      -H "Authorization: ShippoToken <API_TOKEN>" \
//      -H "Content-Type: application/json"  \
//      -d '{
//         "address_from":{
//            "name":"Mr. Hippo",
//            "street1":"215 Clayton St.",
//            "city":"San Francisco",
//            "state":"CA",
//            "zip":"94117",
//            "country":"US"
//         },
//         "address_to":{
//            "name":"Mrs. Hippo",
//            "street1":"965 Mission St.",
//            "city":"San Francisco",
//            "state":"CA",
//            "zip":"94105",
//            "country":"US"
//         },
//         "parcels":[{
//            "length":"5",
//            "width":"5",
//            "height":"5",
//            "distance_unit":"in",
//            "weight":"2",
//            "mass_unit":"lb"
//         }],
//         "async": false
//      }'

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

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

//  {
//    "address_from": {
//      "name": "Mr. Hippo",
//      "street1": "215 Clayton St.",
//      "city": "San Francisco",
//      "state": "CA",
//      "zip": "94117",
//      "country": "US"
//    },
//    "address_to": {
//      "name": "Mrs. Hippo",
//      "street1": "965 Mission St.",
//      "city": "San Francisco",
//      "state": "CA",
//      "zip": "94105",
//      "country": "US"
//    },
//    "parcels": [
//      {
//        "length": "5",
//        "width": "5",
//        "height": "5",
//        "distance_unit": "in",
//        "weight": "2",
//        "mass_unit": "lb"
//      }
//    ],
//    "async": false
//  }

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("address_from.name", "Mr. Hippo")
oJson:UpdateString("address_from.street1", "215 Clayton St.")
oJson:UpdateString("address_from.city", "San Francisco")
oJson:UpdateString("address_from.state", "CA")
oJson:UpdateString("address_from.zip", "94117")
oJson:UpdateString("address_from.country", "US")
oJson:UpdateString("address_to.name", "Mrs. Hippo")
oJson:UpdateString("address_to.street1", "965 Mission St.")
oJson:UpdateString("address_to.city", "San Francisco")
oJson:UpdateString("address_to.state", "CA")
oJson:UpdateString("address_to.zip", "94105")
oJson:UpdateString("address_to.country", "US")
oJson:UpdateString("parcels[0].length", "5")
oJson:UpdateString("parcels[0].width", "5")
oJson:UpdateString("parcels[0].height", "5")
oJson:UpdateString("parcels[0].distance_unit", "in")
oJson:UpdateString("parcels[0].weight", "2")
oJson:UpdateString("parcels[0].mass_unit", "lb")
oJson:UpdateBool("async", 0)

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

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://api.goshippo.com/shipments/", 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)

//  {
//    "carrier_accounts": [
//    ],
//    "object_created": "2019-06-28T17:45:20.441Z",
//    "object_updated": "2019-06-28T17:45:20.511Z",
//    "object_id": "17b01795a4884d8a9002ccc17c9d09d1",
//    "object_owner": "admin@chilkatsoft.com",
//    "status": "SUCCESS",
//    "address_from": {
//      "object_id": "427489906b604f498f7bd2429ab7d9a1",
//      "is_complete": true,
//      "name": "Mr. Hippo",
//      "company": "",
//      "street_no": "",
//      "street1": "215 Clayton St.",
//      "validation_results": {},
//      "street2": "",
//      "street3": "",
//      "city": "San Francisco",
//      "state": "CA",
//      "zip": "94117",
//      "country": "US",
//      "phone": "",
//      "email": "",
//      "is_residential": null,
//      "test": true
//    },
//    "address_to": {
//      "object_id": "3d7166269a2844b7842ef9ace942ec7c",
//      "is_complete": true,
//      "name": "Mrs. Hippo",
//      "company": "",
//      "street_no": "",
//      "street1": "965 Mission St.",
//      "validation_results": {},
//      "street2": "",
//      "street3": "",
//      "city": "San Francisco",
//      "state": "CA",
//      "zip": "94105",
//      "country": "US",
//      "phone": "",
//      "email": "",
//      "is_residential": null,
//      "test": true
//    },
//    "parcels": [
//      {
//        "object_state": "VALID",
//        "object_created": "2019-06-28T17:45:20.411Z",
//        "object_updated": "2019-06-28T17:45:20.455Z",
//        "object_id": "5af766ff15684a4186b0e3c833348fac",
//        "object_owner": "admin@chilkatsoft.com",
//        "template": null,
//        "extra": {},
//        "length": "5.0000",
//        "width": "5.0000",
//        "height": "5.0000",
//        "distance_unit": "in",
//        "weight": "2.0000",
//        "mass_unit": "lb",
//        "value_amount": null,
//        "value_currency": null,
//        "metadata": "",
//        "line_items": [
//        ],
//        "test": true
//      }
//    ],
//    "shipment_date": "2019-06-28T17:45:20.511Z",
//    "address_return": {
//      "object_id": "427489906b604f498f7bd2429ab7d9a1",
//      "is_complete": true,
//      "name": "Mr. Hippo",
//      "company": "",
//      "street_no": "",
//      "street1": "215 Clayton St.",
//      "validation_results": {},
//      "street2": "",
//      "street3": "",
//      "city": "San Francisco",
//      "state": "CA",
//      "zip": "94117",
//      "country": "US",
//      "phone": "",
//      "email": "",
//      "is_residential": null,
//      "test": true
//    },
//    "alternate_address_to": null,
//    "customs_declaration": null,
//    "extra": {},
//    "rates": [
//      {
//        "object_created": "2019-06-28T17:45:20.789Z",
//        "object_id": "dd7556c284e8444294d2ab7099e662d2",
//        "object_owner": "admin@chilkatsoft.com",
//        "shipment": "17b01795a4884d8a9002ccc17c9d09d1",
//        "attributes": [
//          "FASTEST"
//        ],
//        "amount": "22.78",
//        "currency": "USD",
//        "amount_local": "22.78",
//        "currency_local": "USD",
//        "provider": "USPS",
//        "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png",
//        "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png",
//        "servicelevel": {
//          "name": "Priority Mail Express",
//          "token": "usps_priority_express",
//          "terms": ""
//        },
//        "estimated_days": 2,
//        "arrives_by": null,
//        "duration_terms": "Overnight delivery to most U.S. locations.",
//        "messages": [
//        ],
//        "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e",
//        "test": true,
//        "zone": "1"
//      },
//      {
//        "object_created": "2019-06-28T17:45:20.786Z",
//        "object_id": "ec11cc297e2f4583986097f6d409e5c6",
//        "object_owner": "admin@chilkatsoft.com",
//        "shipment": "17b01795a4884d8a9002ccc17c9d09d1",
//        "attributes": [
//          "BESTVALUE",
//          "CHEAPEST",
//          "FASTEST"
//        ],
//        "amount": "6.95",
//        "currency": "USD",
//        "amount_local": "6.95",
//        "currency_local": "USD",
//        "provider": "USPS",
//        "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png",
//        "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png",
//        "servicelevel": {
//          "name": "Priority Mail",
//          "token": "usps_priority",
//          "terms": ""
//        },
//        "estimated_days": 2,
//        "arrives_by": null,
//        "duration_terms": "Delivery within 1, 2, or 3 days based on where your package started and where it’s being sent.",
//        "messages": [
//        ],
//        "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e",
//        "test": true,
//        "zone": "1"
//      },
//      {
//        "object_created": "2019-06-28T17:45:20.785Z",
//        "object_id": "d256586f539f4c93a2f02cc11f4942ac",
//        "object_owner": "admin@chilkatsoft.com",
//        "shipment": "17b01795a4884d8a9002ccc17c9d09d1",
//        "attributes": [
//        ],
//        "amount": "7.32",
//        "currency": "USD",
//        "amount_local": "7.32",
//        "currency_local": "USD",
//        "provider": "USPS",
//        "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png",
//        "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png",
//        "servicelevel": {
//          "name": "Parcel Select",
//          "token": "usps_parcel_select",
//          "terms": ""
//        },
//        "estimated_days": 7,
//        "arrives_by": null,
//        "duration_terms": "Delivery in 2 to 8 days.",
//        "messages": [
//        ],
//        "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e",
//        "test": true,
//        "zone": "1"
//      }
//    ],
//    "messages": [
//      {
//        "source": "DHLExpress",
//        "code": "",
//        "text": "Shippo's DHL Express master account doesn't support shipments to inside of the US"
//      }
//    ],
//    "metadata": "",
//    "test": true,
//    "order": null
//  }

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

cObject_created := oJResp:StringOf("object_created")
cObject_updated := oJResp:StringOf("object_updated")
cObject_id := oJResp:StringOf("object_id")
cObject_owner := oJResp:StringOf("object_owner")
cStatus := oJResp:StringOf("status")
cAddress_fromObject_id := oJResp:StringOf("address_from.object_id")
nAddress_fromIs_complete := oJResp:BoolOf("address_from.is_complete")
cAddress_fromName := oJResp:StringOf("address_from.name")
cAddress_fromCompany := oJResp:StringOf("address_from.company")
cAddress_fromStreet_no := oJResp:StringOf("address_from.street_no")
cAddress_fromStreet1 := oJResp:StringOf("address_from.street1")
cAddress_fromStreet2 := oJResp:StringOf("address_from.street2")
cAddress_fromStreet3 := oJResp:StringOf("address_from.street3")
cAddress_fromCity := oJResp:StringOf("address_from.city")
cAddress_fromState := oJResp:StringOf("address_from.state")
cAddress_fromZip := oJResp:StringOf("address_from.zip")
cAddress_fromCountry := oJResp:StringOf("address_from.country")
cAddress_fromPhone := oJResp:StringOf("address_from.phone")
cAddress_fromEmail := oJResp:StringOf("address_from.email")
cAddress_fromIs_residential := oJResp:StringOf("address_from.is_residential")
nAddress_fromTest := oJResp:BoolOf("address_from.test")
cAddress_toObject_id := oJResp:StringOf("address_to.object_id")
nAddress_toIs_complete := oJResp:BoolOf("address_to.is_complete")
cAddress_toName := oJResp:StringOf("address_to.name")
cAddress_toCompany := oJResp:StringOf("address_to.company")
cAddress_toStreet_no := oJResp:StringOf("address_to.street_no")
cAddress_toStreet1 := oJResp:StringOf("address_to.street1")
cAddress_toStreet2 := oJResp:StringOf("address_to.street2")
cAddress_toStreet3 := oJResp:StringOf("address_to.street3")
cAddress_toCity := oJResp:StringOf("address_to.city")
cAddress_toState := oJResp:StringOf("address_to.state")
cAddress_toZip := oJResp:StringOf("address_to.zip")
cAddress_toCountry := oJResp:StringOf("address_to.country")
cAddress_toPhone := oJResp:StringOf("address_to.phone")
cAddress_toEmail := oJResp:StringOf("address_to.email")
cAddress_toIs_residential := oJResp:StringOf("address_to.is_residential")
nAddress_toTest := oJResp:BoolOf("address_to.test")
cShipment_date := oJResp:StringOf("shipment_date")
cAddress_returnObject_id := oJResp:StringOf("address_return.object_id")
nAddress_returnIs_complete := oJResp:BoolOf("address_return.is_complete")
cAddress_returnName := oJResp:StringOf("address_return.name")
cAddress_returnCompany := oJResp:StringOf("address_return.company")
cAddress_returnStreet_no := oJResp:StringOf("address_return.street_no")
cAddress_returnStreet1 := oJResp:StringOf("address_return.street1")
cAddress_returnStreet2 := oJResp:StringOf("address_return.street2")
cAddress_returnStreet3 := oJResp:StringOf("address_return.street3")
cAddress_returnCity := oJResp:StringOf("address_return.city")
cAddress_returnState := oJResp:StringOf("address_return.state")
cAddress_returnZip := oJResp:StringOf("address_return.zip")
cAddress_returnCountry := oJResp:StringOf("address_return.country")
cAddress_returnPhone := oJResp:StringOf("address_return.phone")
cAddress_returnEmail := oJResp:StringOf("address_return.email")
cAddress_returnIs_residential := oJResp:StringOf("address_return.is_residential")
nAddress_returnTest := oJResp:BoolOf("address_return.test")
cAlternate_address_to := oJResp:StringOf("alternate_address_to")
cCustoms_declaration := oJResp:StringOf("customs_declaration")
cMetadata := oJResp:StringOf("metadata")
nTest := oJResp:BoolOf("test")
cOrder := oJResp:StringOf("order")
i := 0
nCount_i := oJResp:SizeOfArray("carrier_accounts")
DO WHILE i < nCount_i
    oJResp:I := i
    i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("parcels")
DO WHILE i < nCount_i
    oJResp:I := i
    cObject_state := oJResp:StringOf("parcels[i].object_state")
    cObject_created := oJResp:StringOf("parcels[i].object_created")
    cObject_updated := oJResp:StringOf("parcels[i].object_updated")
    cObject_id := oJResp:StringOf("parcels[i].object_id")
    cObject_owner := oJResp:StringOf("parcels[i].object_owner")
    cTemplate := oJResp:StringOf("parcels[i].template")
    cLength := oJResp:StringOf("parcels[i].length")
    cWidth := oJResp:StringOf("parcels[i].width")
    cHeight := oJResp:StringOf("parcels[i].height")
    cDistance_unit := oJResp:StringOf("parcels[i].distance_unit")
    cWeight := oJResp:StringOf("parcels[i].weight")
    cMass_unit := oJResp:StringOf("parcels[i].mass_unit")
    cValue_amount := oJResp:StringOf("parcels[i].value_amount")
    cValue_currency := oJResp:StringOf("parcels[i].value_currency")
    cMetadata := oJResp:StringOf("parcels[i].metadata")
    nTest := oJResp:BoolOf("parcels[i].test")
    j := 0
    nCount_j := oJResp:SizeOfArray("parcels[i].line_items")
    DO WHILE j < nCount_j
        oJResp:J := j
        j := j + 1
    ENDDO
    i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("rates")
DO WHILE i < nCount_i
    oJResp:I := i
    cObject_created := oJResp:StringOf("rates[i].object_created")
    cObject_id := oJResp:StringOf("rates[i].object_id")
    cObject_owner := oJResp:StringOf("rates[i].object_owner")
    cShipment := oJResp:StringOf("rates[i].shipment")
    cAmount := oJResp:StringOf("rates[i].amount")
    cCurrency := oJResp:StringOf("rates[i].currency")
    cAmount_local := oJResp:StringOf("rates[i].amount_local")
    cCurrency_local := oJResp:StringOf("rates[i].currency_local")
    cProvider := oJResp:StringOf("rates[i].provider")
    cProvider_image_75 := oJResp:StringOf("rates[i].provider_image_75")
    cProvider_image_200 := oJResp:StringOf("rates[i].provider_image_200")
    cServicelevelName := oJResp:StringOf("rates[i].servicelevel.name")
    cServicelevelToken := oJResp:StringOf("rates[i].servicelevel.token")
    cServicelevelTerms := oJResp:StringOf("rates[i].servicelevel.terms")
    nEstimated_days := oJResp:IntOf("rates[i].estimated_days")
    cArrives_by := oJResp:StringOf("rates[i].arrives_by")
    cDuration_terms := oJResp:StringOf("rates[i].duration_terms")
    cCarrier_account := oJResp:StringOf("rates[i].carrier_account")
    nTest := oJResp:BoolOf("rates[i].test")
    cZone := oJResp:StringOf("rates[i].zone")
    j := 0
    nCount_j := oJResp:SizeOfArray("rates[i].attributes")
    DO WHILE j < nCount_j
        oJResp:J := j
        cStrVal := oJResp:StringOf("rates[i].attributes[j]")
        j := j + 1
    ENDDO
    j := 0
    nCount_j := oJResp:SizeOfArray("rates[i].messages")
    DO WHILE j < nCount_j
        oJResp:J := j
        j := j + 1
    ENDDO
    i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("messages")
DO WHILE i < nCount_i
    oJResp:I := i
    cSource := oJResp:StringOf("messages[i].source")
    cCode := oJResp:StringOf("messages[i].code")
    cText := oJResp:StringOf("messages[i].text")
    i := i + 1
ENDDO

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