Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(DataFlex) Shippo Adding Metadata

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

For more information, see https://goshippo.com/docs/tracking/

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sObject_created
    String sObject_updated
    String sObject_id
    String sStatus
    String sStatus_details
    String sStatus_date
    String sSubstatus
    String sLocationCity
    String sLocationState
    String sLocationZip
    String sLocationCountry
    String sCarrier
    String sTracking_number
    String sAddress_fromCity
    String sAddress_fromState
    String sAddress_fromZip
    String sAddress_fromCountry
    String sAddress_toCity
    String sAddress_toState
    String sAddress_toZip
    String sAddress_toCountry
    String sEta
    String sOriginal_eta
    String sServicelevelToken
    String sServicelevelName
    String sMetadata
    String sTracking_statusObject_created
    String sTracking_statusObject_updated
    String sTracking_statusObject_id
    String sTracking_statusStatus
    String sTracking_statusStatus_details
    String sTracking_statusStatus_date
    String sTracking_statusSubstatus
    String sTracking_statusLocationCity
    String sTracking_statusLocationState
    String sTracking_statusLocationZip
    String sTracking_statusLocationCountry
    String sTransaction
    Boolean iTest
    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

    // 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"

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/tracks/"
    Set ComContentType Of hoReq To "application/x-www-form-urlencoded"
    Send ComAddParam To hoReq "carrier" "shippo"
    Send ComAddParam To hoReq "tracking_number" "SHIPPO_TRANSIT"
    Send ComAddParam To hoReq "metadata" "Order 000123"

    Send ComAddHeader To hoReq "Authorization" "ShippoToken <API_TOKEN>"

    Get pvComObject of hoReq to vReq
    Get ComPostUrlEncoded Of hoHttp "https://api.goshippo.com/tracks/" vReq 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)

    // {
    //   "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

    Get ComStringOf Of hoJResp "carrier" To sCarrier
    Get ComStringOf Of hoJResp "tracking_number" To sTracking_number
    Get ComStringOf Of hoJResp "address_from.city" To sAddress_fromCity
    Get ComStringOf Of hoJResp "address_from.state" To sAddress_fromState
    Get ComStringOf Of hoJResp "address_from.zip" To sAddress_fromZip
    Get ComStringOf Of hoJResp "address_from.country" To sAddress_fromCountry
    Get ComStringOf Of hoJResp "address_to.city" To sAddress_toCity
    Get ComStringOf Of hoJResp "address_to.state" To sAddress_toState
    Get ComStringOf Of hoJResp "address_to.zip" To sAddress_toZip
    Get ComStringOf Of hoJResp "address_to.country" To sAddress_toCountry
    Get ComStringOf Of hoJResp "eta" To sEta
    Get ComStringOf Of hoJResp "original_eta" To sOriginal_eta
    Get ComStringOf Of hoJResp "servicelevel.token" To sServicelevelToken
    Get ComStringOf Of hoJResp "servicelevel.name" To sServicelevelName
    Get ComStringOf Of hoJResp "metadata" To sMetadata
    Get ComStringOf Of hoJResp "tracking_status.object_created" To sTracking_statusObject_created
    Get ComStringOf Of hoJResp "tracking_status.object_updated" To sTracking_statusObject_updated
    Get ComStringOf Of hoJResp "tracking_status.object_id" To sTracking_statusObject_id
    Get ComStringOf Of hoJResp "tracking_status.status" To sTracking_statusStatus
    Get ComStringOf Of hoJResp "tracking_status.status_details" To sTracking_statusStatus_details
    Get ComStringOf Of hoJResp "tracking_status.status_date" To sTracking_statusStatus_date
    Get ComStringOf Of hoJResp "tracking_status.substatus" To sTracking_statusSubstatus
    Get ComStringOf Of hoJResp "tracking_status.location.city" To sTracking_statusLocationCity
    Get ComStringOf Of hoJResp "tracking_status.location.state" To sTracking_statusLocationState
    Get ComStringOf Of hoJResp "tracking_status.location.zip" To sTracking_statusLocationZip
    Get ComStringOf Of hoJResp "tracking_status.location.country" To sTracking_statusLocationCountry
    Get ComStringOf Of hoJResp "transaction" To sTransaction
    Get ComBoolOf Of hoJResp "test" To iTest
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "messages" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Move i + 1 To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "tracking_history" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "tracking_history[i].object_created" To sObject_created
        Get ComStringOf Of hoJResp "tracking_history[i].object_updated" To sObject_updated
        Get ComStringOf Of hoJResp "tracking_history[i].object_id" To sObject_id
        Get ComStringOf Of hoJResp "tracking_history[i].status" To sStatus
        Get ComStringOf Of hoJResp "tracking_history[i].status_details" To sStatus_details
        Get ComStringOf Of hoJResp "tracking_history[i].status_date" To sStatus_date
        Get ComStringOf Of hoJResp "tracking_history[i].substatus" To sSubstatus
        Get ComStringOf Of hoJResp "tracking_history[i].location.city" To sLocationCity
        Get ComStringOf Of hoJResp "tracking_history[i].location.state" To sLocationState
        Get ComStringOf Of hoJResp "tracking_history[i].location.zip" To sLocationZip
        Get ComStringOf Of hoJResp "tracking_history[i].location.country" To sLocationCountry
        Move i + 1 To i
    Loop



End_Procedure

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.