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 Label PurchaseDemonstrates how to create a shipping label in one API call through Shippo. 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 lcStatus LOCAL lcObject_created LOCAL lcObject_updated LOCAL lcObject_id LOCAL lcObject_owner LOCAL lnWas_test LOCAL lcRateObject_id LOCAL lcRateAmount LOCAL lcRateCurrency LOCAL lcRateAmount_local LOCAL lcRateCurrency_local LOCAL lcRateProvider LOCAL lcRateServicelevel_name LOCAL lcRateServicelevel_token LOCAL lcRateCarrier_account LOCAL lcTracking_number LOCAL lcTracking_statusObject_created LOCAL lcTracking_statusObject_id LOCAL lcTracking_statusStatus LOCAL lcTracking_statusStatus_details LOCAL lcTracking_statusStatus_date LOCAL lcTracking_url_provider LOCAL lcEta LOCAL lcLabel_url LOCAL lcCommercial_invoice_url LOCAL lcMetadata 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/transactions/ \ * -H "Authorization: ShippoToken <API_Token>" \ * -H "Content-Type: application/json" \ * -d '{ * "shipment": { * "address_from": { * "name": "Mr. Hippo", * "street1": "215 Clayton St.", * "city": "San Francisco", * "state": "CA", * "zip": "94117", * "country": "US", * "phone": "+1 555 341 9393", * "email": "support@goshippo.com" * }, * "address_to": { * "name": "Mrs. Hippo", * "street1": "965 Mission St.", * "city": "San Francisco", * "state": "CA", * "zip": "94105", * "country": "US", * "phone": "+1 555 341 9393", * "email": "support@goshippo.com" * }, * "parcels": [{ * "length": "5", * "width": "5", * "height": "5", * "distance_unit": "in", * "weight": "2", * "mass_unit": "lb" * }] * }, * "carrier_account": "b741b99f95e841639b54272834bc478c", * "servicelevel_token": "usps_priority" * }' * Use this online tool to generate code from sample JSON: * Generate Code to Create JSON * The following JSON is sent in the request body. * { * "shipment": { * "address_from": { * "name": "Mr. Hippo", * "street1": "215 Clayton St.", * "city": "San Francisco", * "state": "CA", * "zip": "94117", * "country": "US", * "phone": "+1 555 341 9393", * "email": "support@goshippo.com" * }, * "address_to": { * "name": "Mrs. Hippo", * "street1": "965 Mission St.", * "city": "San Francisco", * "state": "CA", * "zip": "94105", * "country": "US", * "phone": "+1 555 341 9393", * "email": "support@goshippo.com" * }, * "parcels": [ * { * "length": "5", * "width": "5", * "height": "5", * "distance_unit": "in", * "weight": "2", * "mass_unit": "lb" * } * ] * }, * "carrier_account": "b741b99f95e841639b54272834bc478c", * "servicelevel_token": "usps_priority" * } * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJson = CreateObject('Chilkat.JsonObject') loJson.UpdateString("shipment.address_from.name","Mr. Hippo") loJson.UpdateString("shipment.address_from.street1","215 Clayton St.") loJson.UpdateString("shipment.address_from.city","San Francisco") loJson.UpdateString("shipment.address_from.state","CA") loJson.UpdateString("shipment.address_from.zip","94117") loJson.UpdateString("shipment.address_from.country","US") loJson.UpdateString("shipment.address_from.phone","+1 555 341 9393") loJson.UpdateString("shipment.address_from.email","support@goshippo.com") loJson.UpdateString("shipment.address_to.name","Mrs. Hippo") loJson.UpdateString("shipment.address_to.street1","965 Mission St.") loJson.UpdateString("shipment.address_to.city","San Francisco") loJson.UpdateString("shipment.address_to.state","CA") loJson.UpdateString("shipment.address_to.zip","94105") loJson.UpdateString("shipment.address_to.country","US") loJson.UpdateString("shipment.address_to.phone","+1 555 341 9393") loJson.UpdateString("shipment.address_to.email","support@goshippo.com") loJson.UpdateString("shipment.parcels[0].length","5") loJson.UpdateString("shipment.parcels[0].width","5") loJson.UpdateString("shipment.parcels[0].height","5") loJson.UpdateString("shipment.parcels[0].distance_unit","in") loJson.UpdateString("shipment.parcels[0].weight","2") loJson.UpdateString("shipment.parcels[0].mass_unit","lb") loJson.UpdateString("carrier_account","b741b99f95e841639b54272834bc478c") loJson.UpdateString("servicelevel_token","usps_priority") loHttp.SetRequestHeader("Authorization","ShippoToken <API_Token>") loHttp.SetRequestHeader("Content-Type","application/json") loResp = loHttp.PostJson3("https://api.goshippo.com/transactions/","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) * { * "object_state": "VALID", * "status": "SUCCESS", * "object_created": "2013-12-27T19:14:48.273Z", * "object_updated": "2013-12-27T19:14:48.273Z", * "object_id": "64bba01845ef40d29374032599f22588", * "object_owner": "shippotle@goshippo.com", * "was_test": false, * "rate": { * "object_id": "cf6fea899f1848b494d9568e8266e076", * "amount": "5.50", * "currency": "USD", * "amount_local": "5.50", * "currency_local": "USD", * "provider": "USPS", * "servicelevel_name": "Priority Mail", * "servicelevel_token": "usps_priority", * "carrier_account": "078870331023437cb917f5187429b093" * }, * "tracking_number": "ZW70QJC", * "tracking_status": { * "object_created": "2013-12-27T23:17:41.411Z", * "object_id": "a21b3d6831c14ceaba6730179ce6e784", * "status": "UNKNOWN", * "status_details": "", * "status_date": "2013-12-28T12:04:04.214Z" * }, * "tracking_url_provider": "https://tools.usps.com/go/TrackConfirmAction.action?tLabels=ZW70QJC", * "eta": "2013-12-30T12:00:00.000Z", * "label_url": "https://shippo-delivery.s3.amazonaws.com/96.pdf?Signature=PEdWrp0mFWAGwJp7FW3b%2FeA2eyY%3D&Expires=1385930652&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA", * "commercial_invoice_url": "", * "metadata": "", * "messages": [ * ] * } * 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_state = loJResp.StringOf("object_state") lcStatus = loJResp.StringOf("status") lcObject_created = loJResp.StringOf("object_created") lcObject_updated = loJResp.StringOf("object_updated") lcObject_id = loJResp.StringOf("object_id") lcObject_owner = loJResp.StringOf("object_owner") lnWas_test = loJResp.BoolOf("was_test") lcRateObject_id = loJResp.StringOf("rate.object_id") lcRateAmount = loJResp.StringOf("rate.amount") lcRateCurrency = loJResp.StringOf("rate.currency") lcRateAmount_local = loJResp.StringOf("rate.amount_local") lcRateCurrency_local = loJResp.StringOf("rate.currency_local") lcRateProvider = loJResp.StringOf("rate.provider") lcRateServicelevel_name = loJResp.StringOf("rate.servicelevel_name") lcRateServicelevel_token = loJResp.StringOf("rate.servicelevel_token") lcRateCarrier_account = loJResp.StringOf("rate.carrier_account") lcTracking_number = loJResp.StringOf("tracking_number") lcTracking_statusObject_created = loJResp.StringOf("tracking_status.object_created") lcTracking_statusObject_id = loJResp.StringOf("tracking_status.object_id") lcTracking_statusStatus = loJResp.StringOf("tracking_status.status") lcTracking_statusStatus_details = loJResp.StringOf("tracking_status.status_details") lcTracking_statusStatus_date = loJResp.StringOf("tracking_status.status_date") lcTracking_url_provider = loJResp.StringOf("tracking_url_provider") lcEta = loJResp.StringOf("eta") lcLabel_url = loJResp.StringOf("label_url") lcCommercial_invoice_url = loJResp.StringOf("commercial_invoice_url") lcMetadata = loJResp.StringOf("metadata") i = 0 lnCount_i = loJResp.SizeOfArray("messages") DO WHILE i < lnCount_i loJResp.I = i i = i + 1 ENDDO RELEASE loHttp RELEASE loJson RELEASE loSbResponseBody RELEASE loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.