Chilkat Examples

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

Visual Basic 6.0 Web API Examples

Primary Categories

ABN AMRO
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
Global Payments
Google Search Console
Hungary NAV Invoicing
Jira
MYOB
Magento
MercadoLibre

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

 

 

 

(Visual Basic 6.0) 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

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

Dim http As New ChilkatHttp
Dim success As Long

' 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"
'     }
'   ]
' }

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

http.SetRequestHeader "Authorization","ShippoToken shippo_test_3af5d574e2f845d30efcaf9b2f47d9c2aef4807a"
http.SetRequestHeader "Content-Type","application/json"

Dim resp As ChilkatHttpResponse
Set resp = http.PostJson3("https://api.goshippo.com/batches/","application/json",json)
If (http.LastMethodSuccess = 0) Then
    Debug.Print http.LastErrorText
    Exit Sub
End If

Dim sbResponseBody As New ChilkatStringBuilder
success = resp.GetBodySb(sbResponseBody)
Dim jResp As New ChilkatJsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0

Debug.Print "Response Body:"
Debug.Print jResp.Emit()

Dim respStatusCode As Long
respStatusCode = resp.StatusCode
Debug.Print "Response Status Code = " & respStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Header:"
    Debug.Print resp.Header
    Debug.Print "Failed."

    Exit Sub
End If

' 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

Dim object_id As String
object_id = jResp.StringOf("object_id")
Dim object_owner As String
object_owner = jResp.StringOf("object_owner")
Dim status As String
status = jResp.StringOf("status")
Dim object_created As String
object_created = jResp.StringOf("object_created")
Dim object_updated As String
object_updated = jResp.StringOf("object_updated")
Dim metadata As String
metadata = jResp.StringOf("metadata")
Dim default_carrier_account As String
default_carrier_account = jResp.StringOf("default_carrier_account")
Dim default_servicelevel_token As String
default_servicelevel_token = jResp.StringOf("default_servicelevel_token")
Dim label_filetype As String
label_filetype = jResp.StringOf("label_filetype")
Dim batch_shipmentsNext As String
batch_shipmentsNext = jResp.StringOf("batch_shipments.next")
Dim batch_shipmentsPrevious As String
batch_shipmentsPrevious = jResp.StringOf("batch_shipments.previous")
Dim object_resultsPurchase_succeeded As Long
object_resultsPurchase_succeeded = jResp.IntOf("object_results.purchase_succeeded")
Dim object_resultsPurchase_failed As Long
object_resultsPurchase_failed = jResp.IntOf("object_results.purchase_failed")
Dim object_resultsCreation_failed As Long
object_resultsCreation_failed = jResp.IntOf("object_results.creation_failed")
Dim object_resultsCreation_succeeded As Long
object_resultsCreation_succeeded = jResp.IntOf("object_results.creation_succeeded")
Dim i As Long
i = 0
Dim count_i As Long
count_i = jResp.SizeOfArray("batch_shipments.results")
Do While i < count_i
    jResp.I = i
    i = i + 1
Loop
i = 0
count_i = jResp.SizeOfArray("label_url")
Do While i < count_i
    jResp.I = i
    i = i + 1
Loop

 

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