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
(Lianja) 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/
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loHttp = createobject("CkHttp") // 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 loReq = createobject("CkHttpRequest") 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 = .F.) then ? loHttp.LastErrorText release loHttp release loReq return endif loSbResponseBody = createobject("CkStringBuilder") loResp.GetBodySb(loSbResponseBody) loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "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 return 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") llWas_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.