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
(PowerBuilder) 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/
integer li_rc oleobject loo_Http integer li_Success oleobject loo_Req oleobject loo_Resp oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_Object_state string ls_Status string ls_Object_created string ls_Object_updated string ls_Object_id string ls_Object_owner integer li_Was_test string ls_RateObject_id string ls_RateAmount string ls_RateCurrency string ls_RateAmount_local string ls_RateCurrency_local string ls_RateProvider string ls_RateServicelevel_name string ls_RateServicelevel_token string ls_RateCarrier_account string ls_Tracking_number string ls_Tracking_statusObject_created string ls_Tracking_statusObject_id string ls_Tracking_statusStatus string ls_Tracking_statusStatus_details string ls_Tracking_statusStatus_date string ls_Tracking_url_provider string ls_Eta string ls_Label_url string ls_Commercial_invoice_url string ls_Metadata integer i integer li_Count_i // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // 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 loo_Req = create oleobject // Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest") loo_Req.HttpVerb = "POST" loo_Req.Path = "/transactions" loo_Req.ContentType = "application/x-www-form-urlencoded" loo_Req.AddParam("rate","ec6143e746094bcab1bdc4c17600dabf") loo_Req.AddParam("label_file_type","PDF") loo_Req.AddParam("async","false") loo_Req.AddHeader("Authorization","ShippoToken <API_TOKEN>") loo_Resp = loo_Http.PostUrlEncoded("https://api.goshippo.com/transactions",loo_Req) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Req return end if loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Resp.GetBodySb(loo_SbResponseBody) loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() li_RespStatusCode = loo_Resp.StatusCode Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Resp.Header Write-Debug "Failed." destroy loo_Resp destroy loo_Http destroy loo_Req destroy loo_SbResponseBody destroy loo_JResp return end if destroy loo_Resp // 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 ls_Object_state = loo_JResp.StringOf("object_state") ls_Status = loo_JResp.StringOf("status") ls_Object_created = loo_JResp.StringOf("object_created") ls_Object_updated = loo_JResp.StringOf("object_updated") ls_Object_id = loo_JResp.StringOf("object_id") ls_Object_owner = loo_JResp.StringOf("object_owner") li_Was_test = loo_JResp.BoolOf("was_test") ls_RateObject_id = loo_JResp.StringOf("rate.object_id") ls_RateAmount = loo_JResp.StringOf("rate.amount") ls_RateCurrency = loo_JResp.StringOf("rate.currency") ls_RateAmount_local = loo_JResp.StringOf("rate.amount_local") ls_RateCurrency_local = loo_JResp.StringOf("rate.currency_local") ls_RateProvider = loo_JResp.StringOf("rate.provider") ls_RateServicelevel_name = loo_JResp.StringOf("rate.servicelevel_name") ls_RateServicelevel_token = loo_JResp.StringOf("rate.servicelevel_token") ls_RateCarrier_account = loo_JResp.StringOf("rate.carrier_account") ls_Tracking_number = loo_JResp.StringOf("tracking_number") ls_Tracking_statusObject_created = loo_JResp.StringOf("tracking_status.object_created") ls_Tracking_statusObject_id = loo_JResp.StringOf("tracking_status.object_id") ls_Tracking_statusStatus = loo_JResp.StringOf("tracking_status.status") ls_Tracking_statusStatus_details = loo_JResp.StringOf("tracking_status.status_details") ls_Tracking_statusStatus_date = loo_JResp.StringOf("tracking_status.status_date") ls_Tracking_url_provider = loo_JResp.StringOf("tracking_url_provider") ls_Eta = loo_JResp.StringOf("eta") ls_Label_url = loo_JResp.StringOf("label_url") ls_Commercial_invoice_url = loo_JResp.StringOf("commercial_invoice_url") ls_Metadata = loo_JResp.StringOf("metadata") i = 0 li_Count_i = loo_JResp.SizeOfArray("messages") do while i < li_Count_i loo_JResp.I = i i = i + 1 loop destroy loo_Http destroy loo_Req destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.