Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois
Mastercard

MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(DataFlex) Shippo Create the Shipment, Get Rates, and Purchase Label

Demonstrates how retrieve rates and create labels for international shipments.

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sTemplate
    String sLength
    String sWidth
    String sHeight
    String sDistance_unit
    String sWeight
    String sMass_unit
    String sValue_amount
    String sValue_currency
    Boolean iTest
    Integer j
    Integer iCount_j
    Integer iIntVal
    String sObject_created
    String sObject_updated
    String sObject_id
    String sObject_owner
    String sStatus
    String sAddress_fromObject_id
    Boolean iAddress_fromIs_complete
    String sAddress_fromCompany
    String sAddress_fromStreet_no
    String sAddress_fromName
    String sAddress_fromStreet1
    String sAddress_fromStreet2
    String sAddress_fromCity
    String sAddress_fromState
    String sAddress_fromZip
    String sAddress_fromCountry
    String sAddress_fromPhone
    String sAddress_fromEmail
    String sAddress_fromIs_residential
    String sAddress_toObject_id
    Boolean iAddress_toIs_complete
    String sAddress_toName
    String sAddress_toStreet1
    String sAddress_toCity
    String sAddress_toState
    String sAddress_toZip
    String sAddress_toCountry
    String sAddress_toPhone
    String sAddress_toEmail
    Boolean iAddress_toIs_residential
    String sAddress_return
    String sShipment_date
    String sExtraInsuranceCurrency
    String sExtraInsuranceAmount
    String sExtraReference_1
    String sExtraReference_2
    String sCustoms_declaration
    String sMetadata
    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/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"
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "contents_type" "MERCHANDISE" To iSuccess
    Get ComUpdateString Of hoJson "non_delivery_option" "RETURN" To iSuccess
    Get ComUpdateBool Of hoJson "certify" True To iSuccess
    Get ComUpdateString Of hoJson "certify_signer" "Simon Kreuz" To iSuccess
    Get ComUpdateString Of hoJson "incoterm" "DDU" To iSuccess
    Get ComUpdateString Of hoJson "items[0].description" "T-shirt" To iSuccess
    Get ComUpdateInt Of hoJson "items[0].quantity" 20 To iSuccess
    Get ComUpdateString Of hoJson "items[0].net_weight" "5" To iSuccess
    Get ComUpdateString Of hoJson "items[0].mass_unit" "lb" To iSuccess
    Get ComUpdateString Of hoJson "items[0].value_amount" "200" To iSuccess
    Get ComUpdateString Of hoJson "items[0].value_currency" "USD" To iSuccess
    Get ComUpdateString Of hoJson "items[0].tariff_number" "" To iSuccess
    Get ComUpdateString Of hoJson "items[0].origin_country" "US" To iSuccess

    Send ComSetRequestHeader To hoHttp "Authorization" "ShippoToken <API_TOKEN>"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.goshippo.com/customs/declarations/" "application/json" vJson 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)

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

    Get ComStringOf Of hoJResp "object_created" To sObject_created
    Get ComStringOf Of hoJResp "object_updated" To sObject_updated
    Get ComStringOf Of hoJResp "object_id" To sObject_id
    Get ComStringOf Of hoJResp "object_owner" To sObject_owner
    Get ComStringOf Of hoJResp "status" To sStatus
    Get ComStringOf Of hoJResp "address_from.object_id" To sAddress_fromObject_id
    Get ComBoolOf Of hoJResp "address_from.is_complete" To iAddress_fromIs_complete
    Get ComStringOf Of hoJResp "address_from.company" To sAddress_fromCompany
    Get ComStringOf Of hoJResp "address_from.street_no" To sAddress_fromStreet_no
    Get ComStringOf Of hoJResp "address_from.name" To sAddress_fromName
    Get ComStringOf Of hoJResp "address_from.street1" To sAddress_fromStreet1
    Get ComStringOf Of hoJResp "address_from.street2" To sAddress_fromStreet2
    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_from.phone" To sAddress_fromPhone
    Get ComStringOf Of hoJResp "address_from.email" To sAddress_fromEmail
    Get ComStringOf Of hoJResp "address_from.is_residential" To sAddress_fromIs_residential
    Get ComStringOf Of hoJResp "address_to.object_id" To sAddress_toObject_id
    Get ComBoolOf Of hoJResp "address_to.is_complete" To iAddress_toIs_complete
    Get ComStringOf Of hoJResp "address_to.name" To sAddress_toName
    Get ComStringOf Of hoJResp "address_to.street1" To sAddress_toStreet1
    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 "address_to.phone" To sAddress_toPhone
    Get ComStringOf Of hoJResp "address_to.email" To sAddress_toEmail
    Get ComBoolOf Of hoJResp "address_to.is_residential" To iAddress_toIs_residential
    Get ComStringOf Of hoJResp "address_return" To sAddress_return
    Get ComStringOf Of hoJResp "shipment_date" To sShipment_date
    Get ComStringOf Of hoJResp "extra.insurance.currency" To sExtraInsuranceCurrency
    Get ComStringOf Of hoJResp "extra.insurance.amount" To sExtraInsuranceAmount
    Get ComStringOf Of hoJResp "extra.reference_1" To sExtraReference_1
    Get ComStringOf Of hoJResp "extra.reference_2" To sExtraReference_2
    Get ComStringOf Of hoJResp "customs_declaration" To sCustoms_declaration
    Get ComStringOf Of hoJResp "metadata" To sMetadata
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "parcels" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "parcels[i].object_id" To sObject_id
        Get ComStringOf Of hoJResp "parcels[i].object_created" To sObject_created
        Get ComStringOf Of hoJResp "parcels[i].object_updated" To sObject_updated
        Get ComStringOf Of hoJResp "parcels[i].object_owner" To sObject_owner
        Get ComStringOf Of hoJResp "parcels[i].template" To sTemplate
        Get ComStringOf Of hoJResp "parcels[i].length" To sLength
        Get ComStringOf Of hoJResp "parcels[i].width" To sWidth
        Get ComStringOf Of hoJResp "parcels[i].height" To sHeight
        Get ComStringOf Of hoJResp "parcels[i].distance_unit" To sDistance_unit
        Get ComStringOf Of hoJResp "parcels[i].weight" To sWeight
        Get ComStringOf Of hoJResp "parcels[i].mass_unit" To sMass_unit
        Get ComStringOf Of hoJResp "parcels[i].value_amount" To sValue_amount
        Get ComStringOf Of hoJResp "parcels[i].value_currency" To sValue_currency
        Get ComStringOf Of hoJResp "parcels[i].metadata" To sMetadata
        Get ComBoolOf Of hoJResp "parcels[i].test" To iTest
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "parcels[i].line_items" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "rates" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "rates[i]" To iIntVal
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "rates[i].attributes" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "rates[i].messages" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "carrier_accounts" 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 "messages" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Move (i + 1) To i
    Loop



End_Procedure

 

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