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 Create Transaction ObjectCreates a Transaction object that represents a shipping label purchase and is based on the shipping rate. For more information, see https://goshippo.com/docs/shipping-labels/
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_Test string ls_Rate string ls_Tracking_number string ls_Tracking_status string ls_Eta string ls_Tracking_url_provider string ls_Label_url string ls_Commercial_invoice_url string ls_Order string ls_Metadata string ls_Parcel 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="478fb066930e4e3195a3686f7ea5b612" // -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","478fb066930e4e3195a3686f7ea5b612") 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": "2019-06-28T18:04:08.679Z", // "object_updated": "2019-06-28T18:04:10.516Z", // "object_id": "6178e155da304f10aa4b4271fdca84fb", // "object_owner": "admin@chilkatsoft.com", // "test": true, // "rate": "dd7556c284e8444294d2ab7099e662d2", // "tracking_number": "92701902416755000000000015", // "tracking_status": "UNKNOWN", // "eta": null, // "tracking_url_provider": "https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=92701902416755000000000015", // "label_url": "https://shippo-delivery-east.s3.amazonaws.com/6178e155da304f10aa4b4271fdca84fb.pdf?Signature=1LU0Qf11nQJGei%2FeLZr%2BQ5EwJS4%3D&Expires=1593281050&AWSAccessKeyId=AKIAJGLCC5MYLLWIG42A", // "commercial_invoice_url": null, // "messages": [ // ], // "order": null, // "metadata": "", // "parcel": "5af766ff15684a4186b0e3c833348fac", // "billing": { // "payments": [ // ] // } // } // 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_Test = loo_JResp.BoolOf("test") ls_Rate = loo_JResp.StringOf("rate") ls_Tracking_number = loo_JResp.StringOf("tracking_number") ls_Tracking_status = loo_JResp.StringOf("tracking_status") ls_Eta = loo_JResp.StringOf("eta") ls_Tracking_url_provider = loo_JResp.StringOf("tracking_url_provider") ls_Label_url = loo_JResp.StringOf("label_url") ls_Commercial_invoice_url = loo_JResp.StringOf("commercial_invoice_url") ls_Order = loo_JResp.StringOf("order") ls_Metadata = loo_JResp.StringOf("metadata") ls_Parcel = loo_JResp.StringOf("parcel") i = 0 li_Count_i = loo_JResp.SizeOfArray("messages") do while i < li_Count_i loo_JResp.I = i i = i + 1 loop i = 0 li_Count_i = loo_JResp.SizeOfArray("billing.payments") 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.