Sample code for 30+ languages & platforms
Xbase++

Shippo Adding Metadata

See more Shippo Examples

Demonstrates how to add metadata to the tracking request through a POST request.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oReq
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cObject_created
LOCAL cObject_updated
LOCAL cObject_id
LOCAL cStatus
LOCAL cStatus_details
LOCAL cStatus_date
LOCAL cSubstatus
LOCAL cLocationCity
LOCAL cLocationState
LOCAL cLocationZip
LOCAL cLocationCountry
LOCAL cCarrier
LOCAL cTracking_number
LOCAL cAddress_fromCity
LOCAL cAddress_fromState
LOCAL cAddress_fromZip
LOCAL cAddress_fromCountry
LOCAL cAddress_toCity
LOCAL cAddress_toState
LOCAL cAddress_toZip
LOCAL cAddress_toCountry
LOCAL cEta
LOCAL cOriginal_eta
LOCAL cServicelevelToken
LOCAL cServicelevelName
LOCAL cMetadata
LOCAL cTracking_statusObject_created
LOCAL cTracking_statusObject_updated
LOCAL cTracking_statusObject_id
LOCAL cTracking_statusStatus
LOCAL cTracking_statusStatus_details
LOCAL cTracking_statusStatus_date
LOCAL cTracking_statusSubstatus
LOCAL cTracking_statusLocationCity
LOCAL cTracking_statusLocationState
LOCAL cTracking_statusLocationZip
LOCAL cTracking_statusLocationCountry
LOCAL cTransaction
LOCAL nTest
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/tracks/ \
//      -H "Authorization: ShippoToken <API_TOKEN>" \
//      -d carrier="shippo" \
//      -d tracking_number="SHIPPO_TRANSIT" \
//      -d metadata="Order 000123"

oReq := CreateObject("Chilkat.HttpRequest")
oReq:HttpVerb := "POST"
oReq:Path := "/tracks/"
oReq:ContentType := "application/x-www-form-urlencoded"
oReq:AddParam("carrier", "shippo")
oReq:AddParam("tracking_number", "SHIPPO_TRANSIT")
oReq:AddParam("metadata", "Order 000123")

oReq:AddHeader("Authorization", "ShippoToken <API_TOKEN>")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpReq("https://api.goshippo.com/tracks/", oReq, oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oReq: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()
    oReq:destroy()
    oResp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    RETURN
ENDIF

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

//  {
//    "messages": [
//    ],
//    "carrier": "shippo",
//    "tracking_number": "SHIPPO_TRANSIT",
//    "address_from": {
//      "city": "San Francisco",
//      "state": "CA",
//      "zip": "94103",
//      "country": "US"
//    },
//    "address_to": {
//      "city": "Chicago",
//      "state": "IL",
//      "zip": "60611",
//      "country": "US"
//    },
//    "eta": "2019-07-07T17:07:44.989Z",
//    "original_eta": "2019-07-07T17:07:44.989Z",
//    "servicelevel": {
//      "token": "shippo_priority",
//      "name": "Priority Mail"
//    },
//    "metadata": "Shippo test tracking",
//    "tracking_status": {
//      "object_created": "2019-07-04T17:07:45.003Z",
//      "object_updated": null,
//      "object_id": "ee35fb56f5d04021b36168abedc04573",
//      "status": "TRANSIT",
//      "status_details": "Your shipment has departed from the origin.",
//      "status_date": "2019-07-03T15:02:45.003Z",
//      "substatus": null,
//      "location": {
//        "city": "San Francisco",
//        "state": "CA",
//        "zip": "94103",
//        "country": "US"
//      }
//    },
//    "tracking_history": [
//      {
//        "object_created": "2019-07-04T17:07:45.005Z",
//        "object_updated": null,
//        "object_id": "2121a59f53ed42e0ae0436f636179156",
//        "status": "UNKNOWN",
//        "status_details": "The carrier has received the electronic shipment information.",
//        "status_date": "2019-07-02T12:57:45.005Z",
//        "substatus": null,
//        "location": {
//          "city": "San Francisco",
//          "state": "CA",
//          "zip": "94103",
//          "country": "US"
//        }
//      },
//      {
//        "object_created": "2019-07-04T17:07:45.005Z",
//        "object_updated": null,
//        "object_id": "06f949db1a8245beaa28df264b368a76",
//        "status": "TRANSIT",
//        "status_details": "Your shipment has departed from the origin.",
//        "status_date": "2019-07-03T15:02:45.005Z",
//        "substatus": null,
//        "location": {
//          "city": "San Francisco",
//          "state": "CA",
//          "zip": "94103",
//          "country": "US"
//        }
//      }
//    ],
//    "transaction": null,
//    "test": true
//  }

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

cCarrier := oJResp:StringOf("carrier")
cTracking_number := oJResp:StringOf("tracking_number")
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_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")
cEta := oJResp:StringOf("eta")
cOriginal_eta := oJResp:StringOf("original_eta")
cServicelevelToken := oJResp:StringOf("servicelevel.token")
cServicelevelName := oJResp:StringOf("servicelevel.name")
cMetadata := oJResp:StringOf("metadata")
cTracking_statusObject_created := oJResp:StringOf("tracking_status.object_created")
cTracking_statusObject_updated := oJResp:StringOf("tracking_status.object_updated")
cTracking_statusObject_id := oJResp:StringOf("tracking_status.object_id")
cTracking_statusStatus := oJResp:StringOf("tracking_status.status")
cTracking_statusStatus_details := oJResp:StringOf("tracking_status.status_details")
cTracking_statusStatus_date := oJResp:StringOf("tracking_status.status_date")
cTracking_statusSubstatus := oJResp:StringOf("tracking_status.substatus")
cTracking_statusLocationCity := oJResp:StringOf("tracking_status.location.city")
cTracking_statusLocationState := oJResp:StringOf("tracking_status.location.state")
cTracking_statusLocationZip := oJResp:StringOf("tracking_status.location.zip")
cTracking_statusLocationCountry := oJResp:StringOf("tracking_status.location.country")
cTransaction := oJResp:StringOf("transaction")
nTest := oJResp:BoolOf("test")
i := 0
nCount_i := oJResp:SizeOfArray("messages")
DO WHILE i < nCount_i
    oJResp:I := i
    i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("tracking_history")
DO WHILE i < nCount_i
    oJResp:I := i
    cObject_created := oJResp:StringOf("tracking_history[i].object_created")
    cObject_updated := oJResp:StringOf("tracking_history[i].object_updated")
    cObject_id := oJResp:StringOf("tracking_history[i].object_id")
    cStatus := oJResp:StringOf("tracking_history[i].status")
    cStatus_details := oJResp:StringOf("tracking_history[i].status_details")
    cStatus_date := oJResp:StringOf("tracking_history[i].status_date")
    cSubstatus := oJResp:StringOf("tracking_history[i].substatus")
    cLocationCity := oJResp:StringOf("tracking_history[i].location.city")
    cLocationState := oJResp:StringOf("tracking_history[i].location.state")
    cLocationZip := oJResp:StringOf("tracking_history[i].location.zip")
    cLocationCountry := oJResp:StringOf("tracking_history[i].location.country")
    i := i + 1
ENDDO

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