Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Shippo Create Shipment ObjectCreate a Shipment object to retrieve rates. It represents a request to ship a given package from the sender to the recipient address. For more information, see https://goshippo.com/docs/shipping-labels/
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/shipments/ \ # -H "Authorization: ShippoToken <API_TOKEN>" \ # -H "Content-Type: application/json" \ # -d '{ # "address_from":{ # "name":"Mr. Hippo", # "street1":"215 Clayton St.", # "city":"San Francisco", # "state":"CA", # "zip":"94117", # "country":"US" # }, # "address_to":{ # "name":"Mrs. Hippo", # "street1":"965 Mission St.", # "city":"San Francisco", # "state":"CA", # "zip":"94105", # "country":"US" # }, # "parcels":[{ # "length":"5", # "width":"5", # "height":"5", # "distance_unit":"in", # "weight":"2", # "mass_unit":"lb" # }], # "async": false # }' # Use this online tool to generate code from sample JSON: # Generate Code to Create JSON # The following JSON is sent in the request body. # { # "address_from": { # "name": "Mr. Hippo", # "street1": "215 Clayton St.", # "city": "San Francisco", # "state": "CA", # "zip": "94117", # "country": "US" # }, # "address_to": { # "name": "Mrs. Hippo", # "street1": "965 Mission St.", # "city": "San Francisco", # "state": "CA", # "zip": "94105", # "country": "US" # }, # "parcels": [ # { # "length": "5", # "width": "5", # "height": "5", # "distance_unit": "in", # "weight": "2", # "mass_unit": "lb" # } # ], # "async": false # } set json [new_CkJsonObject] CkJsonObject_UpdateString $json "address_from.name" "Mr. Hippo" CkJsonObject_UpdateString $json "address_from.street1" "215 Clayton St." CkJsonObject_UpdateString $json "address_from.city" "San Francisco" CkJsonObject_UpdateString $json "address_from.state" "CA" CkJsonObject_UpdateString $json "address_from.zip" "94117" CkJsonObject_UpdateString $json "address_from.country" "US" CkJsonObject_UpdateString $json "address_to.name" "Mrs. Hippo" CkJsonObject_UpdateString $json "address_to.street1" "965 Mission St." CkJsonObject_UpdateString $json "address_to.city" "San Francisco" CkJsonObject_UpdateString $json "address_to.state" "CA" CkJsonObject_UpdateString $json "address_to.zip" "94105" CkJsonObject_UpdateString $json "address_to.country" "US" CkJsonObject_UpdateString $json "parcels[0].length" "5" CkJsonObject_UpdateString $json "parcels[0].width" "5" CkJsonObject_UpdateString $json "parcels[0].height" "5" CkJsonObject_UpdateString $json "parcels[0].distance_unit" "in" CkJsonObject_UpdateString $json "parcels[0].weight" "2" CkJsonObject_UpdateString $json "parcels[0].mass_unit" "lb" CkJsonObject_UpdateBool $json "async" 0 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/shipments/" "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) # { # "carrier_accounts": [ # ], # "object_created": "2019-06-28T17:45:20.441Z", # "object_updated": "2019-06-28T17:45:20.511Z", # "object_id": "17b01795a4884d8a9002ccc17c9d09d1", # "object_owner": "admin@chilkatsoft.com", # "status": "SUCCESS", # "address_from": { # "object_id": "427489906b604f498f7bd2429ab7d9a1", # "is_complete": true, # "name": "Mr. Hippo", # "company": "", # "street_no": "", # "street1": "215 Clayton St.", # "validation_results": {}, # "street2": "", # "street3": "", # "city": "San Francisco", # "state": "CA", # "zip": "94117", # "country": "US", # "phone": "", # "email": "", # "is_residential": null, # "test": true # }, # "address_to": { # "object_id": "3d7166269a2844b7842ef9ace942ec7c", # "is_complete": true, # "name": "Mrs. Hippo", # "company": "", # "street_no": "", # "street1": "965 Mission St.", # "validation_results": {}, # "street2": "", # "street3": "", # "city": "San Francisco", # "state": "CA", # "zip": "94105", # "country": "US", # "phone": "", # "email": "", # "is_residential": null, # "test": true # }, # "parcels": [ # { # "object_state": "VALID", # "object_created": "2019-06-28T17:45:20.411Z", # "object_updated": "2019-06-28T17:45:20.455Z", # "object_id": "5af766ff15684a4186b0e3c833348fac", # "object_owner": "admin@chilkatsoft.com", # "template": null, # "extra": {}, # "length": "5.0000", # "width": "5.0000", # "height": "5.0000", # "distance_unit": "in", # "weight": "2.0000", # "mass_unit": "lb", # "value_amount": null, # "value_currency": null, # "metadata": "", # "line_items": [ # ], # "test": true # } # ], # "shipment_date": "2019-06-28T17:45:20.511Z", # "address_return": { # "object_id": "427489906b604f498f7bd2429ab7d9a1", # "is_complete": true, # "name": "Mr. Hippo", # "company": "", # "street_no": "", # "street1": "215 Clayton St.", # "validation_results": {}, # "street2": "", # "street3": "", # "city": "San Francisco", # "state": "CA", # "zip": "94117", # "country": "US", # "phone": "", # "email": "", # "is_residential": null, # "test": true # }, # "alternate_address_to": null, # "customs_declaration": null, # "extra": {}, # "rates": [ # { # "object_created": "2019-06-28T17:45:20.789Z", # "object_id": "dd7556c284e8444294d2ab7099e662d2", # "object_owner": "admin@chilkatsoft.com", # "shipment": "17b01795a4884d8a9002ccc17c9d09d1", # "attributes": [ # "FASTEST" # ], # "amount": "22.78", # "currency": "USD", # "amount_local": "22.78", # "currency_local": "USD", # "provider": "USPS", # "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png", # "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png", # "servicelevel": { # "name": "Priority Mail Express", # "token": "usps_priority_express", # "terms": "" # }, # "estimated_days": 2, # "arrives_by": null, # "duration_terms": "Overnight delivery to most U.S. locations.", # "messages": [ # ], # "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e", # "test": true, # "zone": "1" # }, # { # "object_created": "2019-06-28T17:45:20.786Z", # "object_id": "ec11cc297e2f4583986097f6d409e5c6", # "object_owner": "admin@chilkatsoft.com", # "shipment": "17b01795a4884d8a9002ccc17c9d09d1", # "attributes": [ # "BESTVALUE", # "CHEAPEST", # "FASTEST" # ], # "amount": "6.95", # "currency": "USD", # "amount_local": "6.95", # "currency_local": "USD", # "provider": "USPS", # "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png", # "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png", # "servicelevel": { # "name": "Priority Mail", # "token": "usps_priority", # "terms": "" # }, # "estimated_days": 2, # "arrives_by": null, # "duration_terms": "Delivery within 1, 2, or 3 days based on where your package started and where it’s being sent.", # "messages": [ # ], # "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e", # "test": true, # "zone": "1" # }, # { # "object_created": "2019-06-28T17:45:20.785Z", # "object_id": "d256586f539f4c93a2f02cc11f4942ac", # "object_owner": "admin@chilkatsoft.com", # "shipment": "17b01795a4884d8a9002ccc17c9d09d1", # "attributes": [ # ], # "amount": "7.32", # "currency": "USD", # "amount_local": "7.32", # "currency_local": "USD", # "provider": "USPS", # "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png", # "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png", # "servicelevel": { # "name": "Parcel Select", # "token": "usps_parcel_select", # "terms": "" # }, # "estimated_days": 7, # "arrives_by": null, # "duration_terms": "Delivery in 2 to 8 days.", # "messages": [ # ], # "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e", # "test": true, # "zone": "1" # } # ], # "messages": [ # { # "source": "DHLExpress", # "code": "", # "text": "Shippo's DHL Express master account doesn't support shipments to inside of the US" # } # ], # "metadata": "", # "test": true, # "order": 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 status [CkJsonObject_stringOf $jResp "status"] set address_fromObject_id [CkJsonObject_stringOf $jResp "address_from.object_id"] set address_fromIs_complete [CkJsonObject_BoolOf $jResp "address_from.is_complete"] set address_fromName [CkJsonObject_stringOf $jResp "address_from.name"] set address_fromCompany [CkJsonObject_stringOf $jResp "address_from.company"] set address_fromStreet_no [CkJsonObject_stringOf $jResp "address_from.street_no"] set address_fromStreet1 [CkJsonObject_stringOf $jResp "address_from.street1"] set address_fromStreet2 [CkJsonObject_stringOf $jResp "address_from.street2"] set address_fromStreet3 [CkJsonObject_stringOf $jResp "address_from.street3"] set address_fromCity [CkJsonObject_stringOf $jResp "address_from.city"] set address_fromState [CkJsonObject_stringOf $jResp "address_from.state"] set address_fromZip [CkJsonObject_stringOf $jResp "address_from.zip"] set address_fromCountry [CkJsonObject_stringOf $jResp "address_from.country"] set address_fromPhone [CkJsonObject_stringOf $jResp "address_from.phone"] set address_fromEmail [CkJsonObject_stringOf $jResp "address_from.email"] set address_fromIs_residential [CkJsonObject_stringOf $jResp "address_from.is_residential"] set address_fromTest [CkJsonObject_BoolOf $jResp "address_from.test"] set address_toObject_id [CkJsonObject_stringOf $jResp "address_to.object_id"] set address_toIs_complete [CkJsonObject_BoolOf $jResp "address_to.is_complete"] set address_toName [CkJsonObject_stringOf $jResp "address_to.name"] set address_toCompany [CkJsonObject_stringOf $jResp "address_to.company"] set address_toStreet_no [CkJsonObject_stringOf $jResp "address_to.street_no"] set address_toStreet1 [CkJsonObject_stringOf $jResp "address_to.street1"] set address_toStreet2 [CkJsonObject_stringOf $jResp "address_to.street2"] set address_toStreet3 [CkJsonObject_stringOf $jResp "address_to.street3"] set address_toCity [CkJsonObject_stringOf $jResp "address_to.city"] set address_toState [CkJsonObject_stringOf $jResp "address_to.state"] set address_toZip [CkJsonObject_stringOf $jResp "address_to.zip"] set address_toCountry [CkJsonObject_stringOf $jResp "address_to.country"] set address_toPhone [CkJsonObject_stringOf $jResp "address_to.phone"] set address_toEmail [CkJsonObject_stringOf $jResp "address_to.email"] set address_toIs_residential [CkJsonObject_stringOf $jResp "address_to.is_residential"] set address_toTest [CkJsonObject_BoolOf $jResp "address_to.test"] set shipment_date [CkJsonObject_stringOf $jResp "shipment_date"] set address_returnObject_id [CkJsonObject_stringOf $jResp "address_return.object_id"] set address_returnIs_complete [CkJsonObject_BoolOf $jResp "address_return.is_complete"] set address_returnName [CkJsonObject_stringOf $jResp "address_return.name"] set address_returnCompany [CkJsonObject_stringOf $jResp "address_return.company"] set address_returnStreet_no [CkJsonObject_stringOf $jResp "address_return.street_no"] set address_returnStreet1 [CkJsonObject_stringOf $jResp "address_return.street1"] set address_returnStreet2 [CkJsonObject_stringOf $jResp "address_return.street2"] set address_returnStreet3 [CkJsonObject_stringOf $jResp "address_return.street3"] set address_returnCity [CkJsonObject_stringOf $jResp "address_return.city"] set address_returnState [CkJsonObject_stringOf $jResp "address_return.state"] set address_returnZip [CkJsonObject_stringOf $jResp "address_return.zip"] set address_returnCountry [CkJsonObject_stringOf $jResp "address_return.country"] set address_returnPhone [CkJsonObject_stringOf $jResp "address_return.phone"] set address_returnEmail [CkJsonObject_stringOf $jResp "address_return.email"] set address_returnIs_residential [CkJsonObject_stringOf $jResp "address_return.is_residential"] set address_returnTest [CkJsonObject_BoolOf $jResp "address_return.test"] set alternate_address_to [CkJsonObject_stringOf $jResp "alternate_address_to"] set customs_declaration [CkJsonObject_stringOf $jResp "customs_declaration"] set metadata [CkJsonObject_stringOf $jResp "metadata"] set test [CkJsonObject_BoolOf $jResp "test"] set order [CkJsonObject_stringOf $jResp "order"] set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "carrier_accounts"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set i [expr $i + 1] } set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "parcels"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set object_state [CkJsonObject_stringOf $jResp "parcels[i].object_state"] set object_created [CkJsonObject_stringOf $jResp "parcels[i].object_created"] set object_updated [CkJsonObject_stringOf $jResp "parcels[i].object_updated"] set object_id [CkJsonObject_stringOf $jResp "parcels[i].object_id"] set object_owner [CkJsonObject_stringOf $jResp "parcels[i].object_owner"] set template [CkJsonObject_stringOf $jResp "parcels[i].template"] set length [CkJsonObject_stringOf $jResp "parcels[i].length"] set width [CkJsonObject_stringOf $jResp "parcels[i].width"] set height [CkJsonObject_stringOf $jResp "parcels[i].height"] set distance_unit [CkJsonObject_stringOf $jResp "parcels[i].distance_unit"] set weight [CkJsonObject_stringOf $jResp "parcels[i].weight"] set mass_unit [CkJsonObject_stringOf $jResp "parcels[i].mass_unit"] set value_amount [CkJsonObject_stringOf $jResp "parcels[i].value_amount"] set value_currency [CkJsonObject_stringOf $jResp "parcels[i].value_currency"] set metadata [CkJsonObject_stringOf $jResp "parcels[i].metadata"] set test [CkJsonObject_BoolOf $jResp "parcels[i].test"] set j 0 set count_j [CkJsonObject_SizeOfArray $jResp "parcels[i].line_items"] while {$j < $count_j} { CkJsonObject_put_J $jResp $j set j [expr $j + 1] } set i [expr $i + 1] } set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "rates"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set object_created [CkJsonObject_stringOf $jResp "rates[i].object_created"] set object_id [CkJsonObject_stringOf $jResp "rates[i].object_id"] set object_owner [CkJsonObject_stringOf $jResp "rates[i].object_owner"] set shipment [CkJsonObject_stringOf $jResp "rates[i].shipment"] set amount [CkJsonObject_stringOf $jResp "rates[i].amount"] set currency [CkJsonObject_stringOf $jResp "rates[i].currency"] set amount_local [CkJsonObject_stringOf $jResp "rates[i].amount_local"] set currency_local [CkJsonObject_stringOf $jResp "rates[i].currency_local"] set provider [CkJsonObject_stringOf $jResp "rates[i].provider"] set provider_image_75 [CkJsonObject_stringOf $jResp "rates[i].provider_image_75"] set provider_image_200 [CkJsonObject_stringOf $jResp "rates[i].provider_image_200"] set servicelevelName [CkJsonObject_stringOf $jResp "rates[i].servicelevel.name"] set servicelevelToken [CkJsonObject_stringOf $jResp "rates[i].servicelevel.token"] set servicelevelTerms [CkJsonObject_stringOf $jResp "rates[i].servicelevel.terms"] set estimated_days [CkJsonObject_IntOf $jResp "rates[i].estimated_days"] set arrives_by [CkJsonObject_stringOf $jResp "rates[i].arrives_by"] set duration_terms [CkJsonObject_stringOf $jResp "rates[i].duration_terms"] set carrier_account [CkJsonObject_stringOf $jResp "rates[i].carrier_account"] set test [CkJsonObject_BoolOf $jResp "rates[i].test"] set zone [CkJsonObject_stringOf $jResp "rates[i].zone"] set j 0 set count_j [CkJsonObject_SizeOfArray $jResp "rates[i].attributes"] while {$j < $count_j} { CkJsonObject_put_J $jResp $j set strVal [CkJsonObject_stringOf $jResp "rates[i].attributes[j]"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $jResp "rates[i].messages"] while {$j < $count_j} { CkJsonObject_put_J $jResp $j set j [expr $j + 1] } set i [expr $i + 1] } set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "messages"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set source [CkJsonObject_stringOf $jResp "messages[i].source"] set code [CkJsonObject_stringOf $jResp "messages[i].code"] set text [CkJsonObject_stringOf $jResp "messages[i].text"] 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.