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 POST to Transaction EndpointDemonstrates how to POST to the Transaction endpoint with your Rate object_id to purchase your international shipping label. For more information, see https://goshippo.com/docs/international/
LOCAL loHttp LOCAL lnSuccess LOCAL loReq 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>" \ * -d rate="ec6143e746094bcab1bdc4c17600dabf" * -d label_file_type="PDF" * -d async=false * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.HttpRequest') loReq = CreateObject('Chilkat.HttpRequest') loReq.HttpVerb = "POST" loReq.Path = "/transactions" loReq.ContentType = "application/x-www-form-urlencoded" loReq.AddParam("rate","ec6143e746094bcab1bdc4c17600dabf") loReq.AddParam("label_file_type","PDF") loReq.AddParam("async","false") loReq.AddHeader("Authorization","ShippoToken <API_TOKEN>") loResp = loHttp.PostUrlEncoded("https://api.goshippo.com/transactions",loReq) IF (loHttp.LastMethodSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loReq 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 loReq 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 loReq RELEASE loSbResponseBody RELEASE loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.