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
(Visual FoxPro) 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/
LOCAL loHttp LOCAL lnSuccess LOCAL loJson LOCAL loResp LOCAL loSbResponseBody LOCAL loJResp LOCAL lnRespStatusCode LOCAL lcObject_state LOCAL lcTemplate LOCAL lcLength LOCAL lcWidth LOCAL lcHeight LOCAL lcDistance_unit LOCAL lcWeight LOCAL lcMass_unit LOCAL lcValue_amount LOCAL lcValue_currency LOCAL j LOCAL lnCount_j LOCAL lcShipment LOCAL lcAmount LOCAL lcCurrency LOCAL lcAmount_local LOCAL lcCurrency_local LOCAL lcProvider LOCAL lcProvider_image_75 LOCAL lcProvider_image_200 LOCAL lcServicelevelName LOCAL lcServicelevelToken LOCAL lcServicelevelTerms LOCAL lnEstimated_days LOCAL lcArrives_by LOCAL lcDuration_terms LOCAL lcCarrier_account LOCAL lcZone LOCAL lcStrVal LOCAL lcSource LOCAL lcCode LOCAL lcText LOCAL lcObject_created LOCAL lcObject_updated LOCAL lcObject_id LOCAL lcObject_owner LOCAL lcStatus LOCAL lcAddress_fromObject_id LOCAL lnAddress_fromIs_complete LOCAL lcAddress_fromName LOCAL lcAddress_fromCompany LOCAL lcAddress_fromStreet_no LOCAL lcAddress_fromStreet1 LOCAL lcAddress_fromStreet2 LOCAL lcAddress_fromStreet3 LOCAL lcAddress_fromCity LOCAL lcAddress_fromState LOCAL lcAddress_fromZip LOCAL lcAddress_fromCountry LOCAL lcAddress_fromPhone LOCAL lcAddress_fromEmail LOCAL lcAddress_fromIs_residential LOCAL lnAddress_fromTest LOCAL lcAddress_toObject_id LOCAL lnAddress_toIs_complete LOCAL lcAddress_toName LOCAL lcAddress_toCompany LOCAL lcAddress_toStreet_no LOCAL lcAddress_toStreet1 LOCAL lcAddress_toStreet2 LOCAL lcAddress_toStreet3 LOCAL lcAddress_toCity LOCAL lcAddress_toState LOCAL lcAddress_toZip LOCAL lcAddress_toCountry LOCAL lcAddress_toPhone LOCAL lcAddress_toEmail LOCAL lcAddress_toIs_residential LOCAL lnAddress_toTest LOCAL lcShipment_date LOCAL lcAddress_returnObject_id LOCAL lnAddress_returnIs_complete LOCAL lcAddress_returnName LOCAL lcAddress_returnCompany LOCAL lcAddress_returnStreet_no LOCAL lcAddress_returnStreet1 LOCAL lcAddress_returnStreet2 LOCAL lcAddress_returnStreet3 LOCAL lcAddress_returnCity LOCAL lcAddress_returnState LOCAL lcAddress_returnZip LOCAL lcAddress_returnCountry LOCAL lcAddress_returnPhone LOCAL lcAddress_returnEmail LOCAL lcAddress_returnIs_residential LOCAL lnAddress_returnTest LOCAL lcAlternate_address_to LOCAL lcCustoms_declaration LOCAL lcMetadata LOCAL lnTest LOCAL lcOrder LOCAL i LOCAL lnCount_i * This example assumes the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.Http') * 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 * } * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJson = CreateObject('Chilkat.JsonObject') loJson.UpdateString("address_from.name","Mr. Hippo") loJson.UpdateString("address_from.street1","215 Clayton St.") loJson.UpdateString("address_from.city","San Francisco") loJson.UpdateString("address_from.state","CA") loJson.UpdateString("address_from.zip","94117") loJson.UpdateString("address_from.country","US") loJson.UpdateString("address_to.name","Mrs. Hippo") loJson.UpdateString("address_to.street1","965 Mission St.") loJson.UpdateString("address_to.city","San Francisco") loJson.UpdateString("address_to.state","CA") loJson.UpdateString("address_to.zip","94105") loJson.UpdateString("address_to.country","US") loJson.UpdateString("parcels[0].length","5") loJson.UpdateString("parcels[0].width","5") loJson.UpdateString("parcels[0].height","5") loJson.UpdateString("parcels[0].distance_unit","in") loJson.UpdateString("parcels[0].weight","2") loJson.UpdateString("parcels[0].mass_unit","lb") loJson.UpdateBool("async",0) loHttp.SetRequestHeader("Authorization","ShippoToken <API_TOKEN>") loHttp.SetRequestHeader("Content-Type","application/json") loResp = loHttp.PostJson3("https://api.goshippo.com/shipments/","application/json",loJson) IF (loHttp.LastMethodSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loJson CANCEL ENDIF * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbResponseBody = CreateObject('Chilkat.StringBuilder') loResp.GetBodySb(loSbResponseBody) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJResp = CreateObject('Chilkat.JsonObject') loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = 0 ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + STR(lnRespStatusCode) IF (lnRespStatusCode >= 400) THEN ? "Response Header:" ? loResp.Header ? "Failed." RELEASE loResp RELEASE loHttp RELEASE loJson RELEASE loSbResponseBody RELEASE loJResp CANCEL ENDIF RELEASE loResp * 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 lcObject_created = loJResp.StringOf("object_created") lcObject_updated = loJResp.StringOf("object_updated") lcObject_id = loJResp.StringOf("object_id") lcObject_owner = loJResp.StringOf("object_owner") lcStatus = loJResp.StringOf("status") lcAddress_fromObject_id = loJResp.StringOf("address_from.object_id") lnAddress_fromIs_complete = loJResp.BoolOf("address_from.is_complete") lcAddress_fromName = loJResp.StringOf("address_from.name") lcAddress_fromCompany = loJResp.StringOf("address_from.company") lcAddress_fromStreet_no = loJResp.StringOf("address_from.street_no") lcAddress_fromStreet1 = loJResp.StringOf("address_from.street1") lcAddress_fromStreet2 = loJResp.StringOf("address_from.street2") lcAddress_fromStreet3 = loJResp.StringOf("address_from.street3") lcAddress_fromCity = loJResp.StringOf("address_from.city") lcAddress_fromState = loJResp.StringOf("address_from.state") lcAddress_fromZip = loJResp.StringOf("address_from.zip") lcAddress_fromCountry = loJResp.StringOf("address_from.country") lcAddress_fromPhone = loJResp.StringOf("address_from.phone") lcAddress_fromEmail = loJResp.StringOf("address_from.email") lcAddress_fromIs_residential = loJResp.StringOf("address_from.is_residential") lnAddress_fromTest = loJResp.BoolOf("address_from.test") lcAddress_toObject_id = loJResp.StringOf("address_to.object_id") lnAddress_toIs_complete = loJResp.BoolOf("address_to.is_complete") lcAddress_toName = loJResp.StringOf("address_to.name") lcAddress_toCompany = loJResp.StringOf("address_to.company") lcAddress_toStreet_no = loJResp.StringOf("address_to.street_no") lcAddress_toStreet1 = loJResp.StringOf("address_to.street1") lcAddress_toStreet2 = loJResp.StringOf("address_to.street2") lcAddress_toStreet3 = loJResp.StringOf("address_to.street3") lcAddress_toCity = loJResp.StringOf("address_to.city") lcAddress_toState = loJResp.StringOf("address_to.state") lcAddress_toZip = loJResp.StringOf("address_to.zip") lcAddress_toCountry = loJResp.StringOf("address_to.country") lcAddress_toPhone = loJResp.StringOf("address_to.phone") lcAddress_toEmail = loJResp.StringOf("address_to.email") lcAddress_toIs_residential = loJResp.StringOf("address_to.is_residential") lnAddress_toTest = loJResp.BoolOf("address_to.test") lcShipment_date = loJResp.StringOf("shipment_date") lcAddress_returnObject_id = loJResp.StringOf("address_return.object_id") lnAddress_returnIs_complete = loJResp.BoolOf("address_return.is_complete") lcAddress_returnName = loJResp.StringOf("address_return.name") lcAddress_returnCompany = loJResp.StringOf("address_return.company") lcAddress_returnStreet_no = loJResp.StringOf("address_return.street_no") lcAddress_returnStreet1 = loJResp.StringOf("address_return.street1") lcAddress_returnStreet2 = loJResp.StringOf("address_return.street2") lcAddress_returnStreet3 = loJResp.StringOf("address_return.street3") lcAddress_returnCity = loJResp.StringOf("address_return.city") lcAddress_returnState = loJResp.StringOf("address_return.state") lcAddress_returnZip = loJResp.StringOf("address_return.zip") lcAddress_returnCountry = loJResp.StringOf("address_return.country") lcAddress_returnPhone = loJResp.StringOf("address_return.phone") lcAddress_returnEmail = loJResp.StringOf("address_return.email") lcAddress_returnIs_residential = loJResp.StringOf("address_return.is_residential") lnAddress_returnTest = loJResp.BoolOf("address_return.test") lcAlternate_address_to = loJResp.StringOf("alternate_address_to") lcCustoms_declaration = loJResp.StringOf("customs_declaration") lcMetadata = loJResp.StringOf("metadata") lnTest = loJResp.BoolOf("test") lcOrder = loJResp.StringOf("order") i = 0 lnCount_i = loJResp.SizeOfArray("carrier_accounts") DO WHILE i < lnCount_i loJResp.I = i i = i + 1 ENDDO i = 0 lnCount_i = loJResp.SizeOfArray("parcels") DO WHILE i < lnCount_i loJResp.I = i lcObject_state = loJResp.StringOf("parcels[i].object_state") lcObject_created = loJResp.StringOf("parcels[i].object_created") lcObject_updated = loJResp.StringOf("parcels[i].object_updated") lcObject_id = loJResp.StringOf("parcels[i].object_id") lcObject_owner = loJResp.StringOf("parcels[i].object_owner") lcTemplate = loJResp.StringOf("parcels[i].template") lcLength = loJResp.StringOf("parcels[i].length") lcWidth = loJResp.StringOf("parcels[i].width") lcHeight = loJResp.StringOf("parcels[i].height") lcDistance_unit = loJResp.StringOf("parcels[i].distance_unit") lcWeight = loJResp.StringOf("parcels[i].weight") lcMass_unit = loJResp.StringOf("parcels[i].mass_unit") lcValue_amount = loJResp.StringOf("parcels[i].value_amount") lcValue_currency = loJResp.StringOf("parcels[i].value_currency") lcMetadata = loJResp.StringOf("parcels[i].metadata") lnTest = loJResp.BoolOf("parcels[i].test") j = 0 lnCount_j = loJResp.SizeOfArray("parcels[i].line_items") DO WHILE j < lnCount_j loJResp.J = j j = j + 1 ENDDO i = i + 1 ENDDO i = 0 lnCount_i = loJResp.SizeOfArray("rates") DO WHILE i < lnCount_i loJResp.I = i lcObject_created = loJResp.StringOf("rates[i].object_created") lcObject_id = loJResp.StringOf("rates[i].object_id") lcObject_owner = loJResp.StringOf("rates[i].object_owner") lcShipment = loJResp.StringOf("rates[i].shipment") lcAmount = loJResp.StringOf("rates[i].amount") lcCurrency = loJResp.StringOf("rates[i].currency") lcAmount_local = loJResp.StringOf("rates[i].amount_local") lcCurrency_local = loJResp.StringOf("rates[i].currency_local") lcProvider = loJResp.StringOf("rates[i].provider") lcProvider_image_75 = loJResp.StringOf("rates[i].provider_image_75") lcProvider_image_200 = loJResp.StringOf("rates[i].provider_image_200") lcServicelevelName = loJResp.StringOf("rates[i].servicelevel.name") lcServicelevelToken = loJResp.StringOf("rates[i].servicelevel.token") lcServicelevelTerms = loJResp.StringOf("rates[i].servicelevel.terms") lnEstimated_days = loJResp.IntOf("rates[i].estimated_days") lcArrives_by = loJResp.StringOf("rates[i].arrives_by") lcDuration_terms = loJResp.StringOf("rates[i].duration_terms") lcCarrier_account = loJResp.StringOf("rates[i].carrier_account") lnTest = loJResp.BoolOf("rates[i].test") lcZone = loJResp.StringOf("rates[i].zone") j = 0 lnCount_j = loJResp.SizeOfArray("rates[i].attributes") DO WHILE j < lnCount_j loJResp.J = j lcStrVal = loJResp.StringOf("rates[i].attributes[j]") j = j + 1 ENDDO j = 0 lnCount_j = loJResp.SizeOfArray("rates[i].messages") DO WHILE j < lnCount_j loJResp.J = j j = j + 1 ENDDO i = i + 1 ENDDO i = 0 lnCount_i = loJResp.SizeOfArray("messages") DO WHILE i < lnCount_i loJResp.I = i lcSource = loJResp.StringOf("messages[i].source") lcCode = loJResp.StringOf("messages[i].code") lcText = loJResp.StringOf("messages[i].text") i = i + 1 ENDDO RELEASE loHttp RELEASE loJson RELEASE loSbResponseBody RELEASE loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.