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
JCC Cyprus
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 a Batch

Demonstrates how to create and purchase up to 10,000 shipments in a single API request.

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

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 sObject_id
    String sObject_owner
    String sStatus
    String sObject_created
    String sObject_updated
    String sMetadata
    String sDefault_carrier_account
    String sDefault_servicelevel_token
    String sLabel_filetype
    String sBatch_shipmentsNext
    String sBatch_shipmentsPrevious
    Integer iObject_resultsPurchase_succeeded
    Integer iObject_resultsPurchase_failed
    Integer iObject_resultsCreation_failed
    Integer iObject_resultsCreation_succeeded
    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

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

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

    // {
    //   "default_carrier_account": "078870331023437cb917f5187429b093",
    //   "default_servicelevel_token": "usps_priority",
    //   "label_filetype": "PDF_4x6",
    //   "metadata": "BATCH #170",
    //   "batch_shipments": [
    //     {
    //       "shipment": {
    //         "address_from": {
    //           "name": "Mr Hippo",
    //           "street1": "965 Mission St",
    //           "street2": "Ste 201",
    //           "city": "San Francisco",
    //           "state": "CA",
    //           "zip": "94103",
    //           "country": "US",
    //           "phone": "4151234567",
    //           "email": "mrhippo@goshippo.com"
    //         },
    //         "address_to": {
    //           "name": "Mrs Hippo",
    //           "company": "",
    //           "street1": "Broadway 1",
    //           "street2": "",
    //           "city": "New York",
    //           "state": "NY",
    //           "zip": "10007",
    //           "country": "US",
    //           "phone": "4151234567",
    //           "email": "mrshippo@goshippo.com"
    //         },
    //         "parcels": [
    //           {
    //             "length": "5",
    //             "width": "5",
    //             "height": "5",
    //             "distance_unit": "in",
    //             "weight": "2",
    //             "mass_unit": "oz"
    //           }
    //         ]
    //       }
    //     },
    //     {
    //       "shipment": {
    //         "address_from": {
    //           "name": "Mr Hippo",
    //           "street1": "1092 Indian Summer Ct",
    //           "city": "San Jose",
    //           "state": "CA",
    //           "zip": "95122",
    //           "country": "US",
    //           "phone": "4151234567",
    //           "email": "mrhippo@goshippo.com"
    //         },
    //         "address_to": {
    //           "name": "Mrs Hippo",
    //           "company": "",
    //           "street1": "Broadway 1",
    //           "street2": "",
    //           "city": "New York",
    //           "state": "NY",
    //           "zip": "10007",
    //           "country": "US",
    //           "phone": "4151234567",
    //           "email": "mrshippo@goshippo.com"
    //         },
    //         "parcels": [
    //           {
    //             "length": "5",
    //             "width": "5",
    //             "height": "5",
    //             "distance_unit": "in",
    //             "weight": "20",
    //             "mass_unit": "lb"
    //           }
    //         ]
    //       },
    //       "carrier_account": "a4391cd4ab974f478f55dc08b5c8e3b3",
    //       "servicelevel_token": "fedex_2_day"
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "default_carrier_account" "078870331023437cb917f5187429b093" To iSuccess
    Get ComUpdateString Of hoJson "default_servicelevel_token" "usps_priority" To iSuccess
    Get ComUpdateString Of hoJson "label_filetype" "PDF_4x6" To iSuccess
    Get ComUpdateString Of hoJson "metadata" "BATCH #170" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.name" "Mr Hippo" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.street1" "965 Mission St" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.street2" "Ste 201" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.city" "San Francisco" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.state" "CA" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.zip" "94103" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.country" "US" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.phone" "4151234567" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_from.email" "mrhippo@goshippo.com" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.name" "Mrs Hippo" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.company" "" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.street1" "Broadway 1" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.street2" "" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.city" "New York" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.state" "NY" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.zip" "10007" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.country" "US" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.phone" "4151234567" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.address_to.email" "mrshippo@goshippo.com" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.parcels[0].length" "5" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.parcels[0].width" "5" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.parcels[0].height" "5" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.parcels[0].distance_unit" "in" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.parcels[0].weight" "2" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[0].shipment.parcels[0].mass_unit" "oz" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.name" "Mr Hippo" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.street1" "1092 Indian Summer Ct" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.city" "San Jose" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.state" "CA" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.zip" "95122" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.country" "US" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.phone" "4151234567" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_from.email" "mrhippo@goshippo.com" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.name" "Mrs Hippo" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.company" "" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.street1" "Broadway 1" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.street2" "" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.city" "New York" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.state" "NY" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.zip" "10007" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.country" "US" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.phone" "4151234567" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.address_to.email" "mrshippo@goshippo.com" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.parcels[0].length" "5" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.parcels[0].width" "5" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.parcels[0].height" "5" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.parcels[0].distance_unit" "in" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.parcels[0].weight" "20" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].shipment.parcels[0].mass_unit" "lb" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].carrier_account" "a4391cd4ab974f478f55dc08b5c8e3b3" To iSuccess
    Get ComUpdateString Of hoJson "batch_shipments[1].servicelevel_token" "fedex_2_day" To iSuccess

    Send ComSetRequestHeader To hoHttp "Authorization" "ShippoToken shippo_test_3af5d574e2f845d30efcaf9b2f47d9c2aef4807a"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.goshippo.com/batches/" "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_id": "a015eb693cca465dbb6523ce6d2e3c65",
    //   "object_owner": "admin",
    //   "status": "VALIDATING",
    //   "object_created": "2016-09-12T15:25:43.465Z",
    //   "object_updated": "2016-09-12T15:25:43.465Z",
    //   "metadata": "BATCH #170",
    //   "default_carrier_account": "078870331023437cb917f5187429b093",
    //   "default_servicelevel_token": "usps_priority",
    //   "label_filetype": "PDF_4x6",
    //   "batch_shipments": {
    //     "next": null,
    //     "previous": null,
    //     "results": [
    //     ]
    //   },
    //   "object_results": {
    //     "purchase_succeeded": 0,
    //     "purchase_failed": 0,
    //     "creation_failed": 0,
    //     "creation_succeeded": 0
    //   },
    //   "label_url": [
    //   ]
    // }

    // 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_id" To sObject_id
    Get ComStringOf Of hoJResp "object_owner" To sObject_owner
    Get ComStringOf Of hoJResp "status" To sStatus
    Get ComStringOf Of hoJResp "object_created" To sObject_created
    Get ComStringOf Of hoJResp "object_updated" To sObject_updated
    Get ComStringOf Of hoJResp "metadata" To sMetadata
    Get ComStringOf Of hoJResp "default_carrier_account" To sDefault_carrier_account
    Get ComStringOf Of hoJResp "default_servicelevel_token" To sDefault_servicelevel_token
    Get ComStringOf Of hoJResp "label_filetype" To sLabel_filetype
    Get ComStringOf Of hoJResp "batch_shipments.next" To sBatch_shipmentsNext
    Get ComStringOf Of hoJResp "batch_shipments.previous" To sBatch_shipmentsPrevious
    Get ComIntOf Of hoJResp "object_results.purchase_succeeded" To iObject_resultsPurchase_succeeded
    Get ComIntOf Of hoJResp "object_results.purchase_failed" To iObject_resultsPurchase_failed
    Get ComIntOf Of hoJResp "object_results.creation_failed" To iObject_resultsCreation_failed
    Get ComIntOf Of hoJResp "object_results.creation_succeeded" To iObject_resultsCreation_succeeded
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "batch_shipments.results" 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 "label_url" 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.