Chilkat Online Tools

DataFlex / ShipEngine Walkthrough / Track a package

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sOccurred_at
    String sDescription
    String sCity_locality
    String sState_province
    String sPostal_code
    String sCountry_code
    String sCompany_name
    String sSigner
    String sEvent_code
    String sTracking_number
    String sStatus_code
    String sStatus_description
    String sCarrier_status_code
    String sCarrier_status_description
    String sShip_date
    String sEstimated_delivery_date
    String sActual_delivery_date
    String sException_description
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateString Of hoQueryParams "carrier_code" "fedex" To iSuccess
    Get ComUpdateString Of hoQueryParams "tracking_number" "555671072708" To iSuccess

    Send ComSetRequestHeader To hoHttp "API-Key" "{{API_KEY}}"

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.shipengine.com/v1/tracking" vQueryParams To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    // {
    //   "tracking_number": "789830651142",
    //   "status_code": "DE",
    //   "status_description": "Delivered",
    //   "carrier_status_code": "DL",
    //   "carrier_status_description": "Delivered",
    //   "ship_date": "2019-09-16T21:55:00Z",
    //   "estimated_delivery_date": null,
    //   "actual_delivery_date": "2019-09-17T20:02:00Z",
    //   "exception_description": null,
    //   "events": [
    //     {
    //       "occurred_at": "2019-09-17T20:02:00Z",
    //       "description": "Delivered",
    //       "city_locality": "Austin",
    //       "state_province": "TX",
    //       "postal_code": "78702",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": "Signature not required",
    //       "event_code": "DL"
    //     },
    //     {
    //       "occurred_at": "2019-09-17T13:13:00Z",
    //       "description": "On FedEx vehicle for delivery",
    //       "city_locality": "AUSTIN",
    //       "state_province": "TX",
    //       "postal_code": "78721",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "OD"
    //     },
    //     {
    //       "occurred_at": "2019-09-17T12:09:00Z",
    //       "description": "At local FedEx facility",
    //       "city_locality": "AUSTIN",
    //       "state_province": "TX",
    //       "postal_code": "78721",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "AR"
    //     },
    //     {
    //       "occurred_at": "2019-09-17T08:05:00Z",
    //       "description": "Departed FedEx location",
    //       "city_locality": "FORT WORTH",
    //       "state_province": "TX",
    //       "postal_code": "76177",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "DP"
    //     },
    //     {
    //       "occurred_at": "2019-09-17T06:22:00Z",
    //       "description": "Arrived at FedEx location",
    //       "city_locality": "FORT WORTH",
    //       "state_province": "TX",
    //       "postal_code": "76177",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "AR"
    //     },
    //     {
    //       "occurred_at": "2019-09-17T03:27:00Z",
    //       "description": "Departed FedEx location",
    //       "city_locality": "OAKLAND",
    //       "state_province": "CA",
    //       "postal_code": "94621",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "DP"
    //     },
    //     {
    //       "occurred_at": "2019-09-17T01:04:00Z",
    //       "description": "Arrived at FedEx location",
    //       "city_locality": "OAKLAND",
    //       "state_province": "CA",
    //       "postal_code": "94621",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "AR"
    //     },
    //     {
    //       "occurred_at": "2019-09-17T00:10:00Z",
    //       "description": "Left FedEx origin facility",
    //       "city_locality": "PETALUMA",
    //       "state_province": "CA",
    //       "postal_code": "94954",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "DP"
    //     },
    //     {
    //       "occurred_at": "2019-09-16T21:55:00Z",
    //       "description": "Picked up",
    //       "city_locality": "PETALUMA",
    //       "state_province": "CA",
    //       "postal_code": "94954",
    //       "country_code": "US",
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "PU"
    //     },
    //     {
    //       "occurred_at": "2019-09-16T15:31:38Z",
    //       "description": "Shipment information sent to FedEx",
    //       "city_locality": null,
    //       "state_province": null,
    //       "postal_code": null,
    //       "country_code": null,
    //       "company_name": null,
    //       "signer": null,
    //       "event_code": "OC"
    //     }
    //   ]
    // }

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

    Get ComStringOf Of hoJResp "tracking_number" To sTracking_number
    Get ComStringOf Of hoJResp "status_code" To sStatus_code
    Get ComStringOf Of hoJResp "status_description" To sStatus_description
    Get ComStringOf Of hoJResp "carrier_status_code" To sCarrier_status_code
    Get ComStringOf Of hoJResp "carrier_status_description" To sCarrier_status_description
    Get ComStringOf Of hoJResp "ship_date" To sShip_date
    Get ComStringOf Of hoJResp "estimated_delivery_date" To sEstimated_delivery_date
    Get ComStringOf Of hoJResp "actual_delivery_date" To sActual_delivery_date
    Get ComStringOf Of hoJResp "exception_description" To sException_description
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "events" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "events[i].occurred_at" To sOccurred_at
        Get ComStringOf Of hoJResp "events[i].description" To sDescription
        Get ComStringOf Of hoJResp "events[i].city_locality" To sCity_locality
        Get ComStringOf Of hoJResp "events[i].state_province" To sState_province
        Get ComStringOf Of hoJResp "events[i].postal_code" To sPostal_code
        Get ComStringOf Of hoJResp "events[i].country_code" To sCountry_code
        Get ComStringOf Of hoJResp "events[i].company_name" To sCompany_name
        Get ComStringOf Of hoJResp "events[i].signer" To sSigner
        Get ComStringOf Of hoJResp "events[i].event_code" To sEvent_code
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -G -d "carrier_code=fedex"
	-d "tracking_number=555671072708"
	-H "API-Key: {{API_KEY}}"
https://api.shipengine.com/v1/tracking

Postman Collection Item JSON

{
  "name": "Track a package",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.shipengine.com/v1/tracking?carrier_code=fedex&tracking_number=555671072708",
      "protocol": "https",
      "host": [
        "api",
        "shipengine",
        "com"
      ],
      "path": [
        "v1",
        "tracking"
      ],
      "query": [
        {
          "key": "carrier_code",
          "value": "stamps_com",
          "disabled": true
        },
        {
          "key": "tracking_number",
          "value": "{{tracking_number}}",
          "disabled": true
        },
        {
          "key": "carrier_code",
          "value": "fedex"
        },
        {
          "key": "tracking_number",
          "value": "555671072708"
        }
      ]
    },
    "description": "This request demonstrates how to get tracking information for a package. The `carrier_code` and `tracking_number` are provided via query parameters."
  },
  "response": [
    {
      "name": "Track a package",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.shipengine.com/v1/tracking?carrier_code=fedex&tracking_number=789830651142",
          "protocol": "https",
          "host": [
            "api",
            "shipengine",
            "com"
          ],
          "path": [
            "v1",
            "tracking"
          ],
          "query": [
            {
              "key": "carrier_code",
              "value": "fedex"
            },
            {
              "key": "tracking_number",
              "value": "789830651142"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 18 Sep 2019 18:50:08 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "3515"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "https://www.shipengine.com"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "x-shipengine-requestid",
          "value": "f4e88104-edb8-4a8f-bd1c-a5d85334bdb1"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"tracking_number\": \"789830651142\",\n    \"status_code\": \"DE\",\n    \"status_description\": \"Delivered\",\n    \"carrier_status_code\": \"DL\",\n    \"carrier_status_description\": \"Delivered\",\n    \"ship_date\": \"2019-09-16T21:55:00Z\",\n    \"estimated_delivery_date\": null,\n    \"actual_delivery_date\": \"2019-09-17T20:02:00Z\",\n    \"exception_description\": null,\n    \"events\": [\n        {\n            \"occurred_at\": \"2019-09-17T20:02:00Z\",\n            \"description\": \"Delivered\",\n            \"city_locality\": \"Austin\",\n            \"state_province\": \"TX\",\n            \"postal_code\": \"78702\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": \"Signature not required\",\n            \"event_code\": \"DL\"\n        },\n        {\n            \"occurred_at\": \"2019-09-17T13:13:00Z\",\n            \"description\": \"On FedEx vehicle for delivery\",\n            \"city_locality\": \"AUSTIN\",\n            \"state_province\": \"TX\",\n            \"postal_code\": \"78721\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"OD\"\n        },\n        {\n            \"occurred_at\": \"2019-09-17T12:09:00Z\",\n            \"description\": \"At local FedEx facility\",\n            \"city_locality\": \"AUSTIN\",\n            \"state_province\": \"TX\",\n            \"postal_code\": \"78721\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"AR\"\n        },\n        {\n            \"occurred_at\": \"2019-09-17T08:05:00Z\",\n            \"description\": \"Departed FedEx location\",\n            \"city_locality\": \"FORT WORTH\",\n            \"state_province\": \"TX\",\n            \"postal_code\": \"76177\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"DP\"\n        },\n        {\n            \"occurred_at\": \"2019-09-17T06:22:00Z\",\n            \"description\": \"Arrived at FedEx location\",\n            \"city_locality\": \"FORT WORTH\",\n            \"state_province\": \"TX\",\n            \"postal_code\": \"76177\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"AR\"\n        },\n        {\n            \"occurred_at\": \"2019-09-17T03:27:00Z\",\n            \"description\": \"Departed FedEx location\",\n            \"city_locality\": \"OAKLAND\",\n            \"state_province\": \"CA\",\n            \"postal_code\": \"94621\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"DP\"\n        },\n        {\n            \"occurred_at\": \"2019-09-17T01:04:00Z\",\n            \"description\": \"Arrived at FedEx location\",\n            \"city_locality\": \"OAKLAND\",\n            \"state_province\": \"CA\",\n            \"postal_code\": \"94621\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"AR\"\n        },\n        {\n            \"occurred_at\": \"2019-09-17T00:10:00Z\",\n            \"description\": \"Left FedEx origin facility\",\n            \"city_locality\": \"PETALUMA\",\n            \"state_province\": \"CA\",\n            \"postal_code\": \"94954\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"DP\"\n        },\n        {\n            \"occurred_at\": \"2019-09-16T21:55:00Z\",\n            \"description\": \"Picked up\",\n            \"city_locality\": \"PETALUMA\",\n            \"state_province\": \"CA\",\n            \"postal_code\": \"94954\",\n            \"country_code\": \"US\",\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"PU\"\n        },\n        {\n            \"occurred_at\": \"2019-09-16T15:31:38Z\",\n            \"description\": \"Shipment information sent to FedEx\",\n            \"city_locality\": null,\n            \"state_province\": null,\n            \"postal_code\": null,\n            \"country_code\": null,\n            \"company_name\": null,\n            \"signer\": null,\n            \"event_code\": \"OC\"\n        }\n    ]\n}"
    }
  ]
}