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

Tcl 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

 

 

 

(Tcl) Shippo Create Customs Declaration

Demonstrates how to create a customs declaration and send a POST request with the necessary information to the Customs Declarations endpoint.

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

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

set http [new_CkHttp]

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

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "contents_type" "MERCHANDISE"
CkJsonObject_UpdateString $json "non_delivery_option" "RETURN"
CkJsonObject_UpdateBool $json "certify" 1
CkJsonObject_UpdateString $json "certify_signer" "Simon Kreuz"
CkJsonObject_UpdateString $json "incoterm" "DDU"
CkJsonObject_UpdateString $json "items[0].description" "T-shirt"
CkJsonObject_UpdateInt $json "items[0].quantity" 20
CkJsonObject_UpdateString $json "items[0].net_weight" "5"
CkJsonObject_UpdateString $json "items[0].mass_unit" "lb"
CkJsonObject_UpdateString $json "items[0].value_amount" "200"
CkJsonObject_UpdateString $json "items[0].value_currency" "USD"
CkJsonObject_UpdateString $json "items[0].tariff_number" ""
CkJsonObject_UpdateString $json "items[0].origin_country" "US"

CkHttp_SetRequestHeader $http "Authorization" "ShippoToken <API_TOKEN>"
CkHttp_SetRequestHeader $http "Content-Type" "application/json"

# resp is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://api.goshippo.com/customs/declarations/" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    exit
}

set sbResponseBody [new_CkStringBuilder]

CkHttpResponse_GetBodySb $resp $sbResponseBody
set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttpResponse_header $resp]
    puts "Failed."
    delete_CkHttpResponse $resp

    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

delete_CkHttpResponse $resp

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

# {
#   "object_created": "2019-07-04T16:00:29.043Z",
#   "object_updated": "2019-07-04T16:00:29.043Z",
#   "object_id": "4a1e6ab7b1ba49ed9bc6cb1a8798e0fd",
#   "object_owner": "admin@chilkatsoft.com",
#   "object_state": "VALID",
#   "address_importer": null,
#   "certify_signer": "Simon Kreuz",
#   "certify": true,
#   "items": [
#     "4096c68693364b7ea0af72fb869ee861"
#   ],
#   "non_delivery_option": "RETURN",
#   "contents_type": "MERCHANDISE",
#   "contents_explanation": "",
#   "exporter_reference": "",
#   "importer_reference": "",
#   "invoice": "",
#   "commercial_invoice": false,
#   "license": "",
#   "certificate": "",
#   "notes": "",
#   "eel_pfc": "",
#   "aes_itn": "",
#   "disclaimer": "",
#   "incoterm": "DDU",
#   "metadata": "",
#   "test": true,
#   "duties_payor": null
# }

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

set object_created [CkJsonObject_stringOf $jResp "object_created"]
set object_updated [CkJsonObject_stringOf $jResp "object_updated"]
set object_id [CkJsonObject_stringOf $jResp "object_id"]
set object_owner [CkJsonObject_stringOf $jResp "object_owner"]
set object_state [CkJsonObject_stringOf $jResp "object_state"]
set address_importer [CkJsonObject_stringOf $jResp "address_importer"]
set certify_signer [CkJsonObject_stringOf $jResp "certify_signer"]
set certify [CkJsonObject_BoolOf $jResp "certify"]
set non_delivery_option [CkJsonObject_stringOf $jResp "non_delivery_option"]
set contents_type [CkJsonObject_stringOf $jResp "contents_type"]
set contents_explanation [CkJsonObject_stringOf $jResp "contents_explanation"]
set exporter_reference [CkJsonObject_stringOf $jResp "exporter_reference"]
set importer_reference [CkJsonObject_stringOf $jResp "importer_reference"]
set invoice [CkJsonObject_stringOf $jResp "invoice"]
set commercial_invoice [CkJsonObject_BoolOf $jResp "commercial_invoice"]
set license [CkJsonObject_stringOf $jResp "license"]
set certificate [CkJsonObject_stringOf $jResp "certificate"]
set notes [CkJsonObject_stringOf $jResp "notes"]
set eel_pfc [CkJsonObject_stringOf $jResp "eel_pfc"]
set aes_itn [CkJsonObject_stringOf $jResp "aes_itn"]
set disclaimer [CkJsonObject_stringOf $jResp "disclaimer"]
set incoterm [CkJsonObject_stringOf $jResp "incoterm"]
set metadata [CkJsonObject_stringOf $jResp "metadata"]
set test [CkJsonObject_BoolOf $jResp "test"]
set duties_payor [CkJsonObject_stringOf $jResp "duties_payor"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "items"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set strVal [CkJsonObject_stringOf $jResp "items[i]"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp

 

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