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
(DataFlex) 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/
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Boolean iSuccess Variant vReq Handle hoReq Variant vResp Handle hoResp Variant vSbResponseBody Handle hoSbResponseBody Handle hoJResp Integer iRespStatusCode String sObject_state String sStatus String sObject_created String sObject_updated String sObject_id String sObject_owner Boolean iTest String sRate String sTracking_number String sTracking_status String sEta String sTracking_url_provider String sLabel_url String sCommercial_invoice_url String sOrder String sMetadata String sParcel Integer i Integer iCount_i String sTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // 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 Get Create (RefClass(cComChilkatHttpRequest)) To hoReq If (Not(IsComObjectCreated(hoReq))) Begin Send CreateComObject of hoReq End Set ComHttpVerb Of hoReq To "POST" Set ComPath Of hoReq To "/transactions" Set ComContentType Of hoReq To "application/x-www-form-urlencoded" Send ComAddParam To hoReq "rate" "478fb066930e4e3195a3686f7ea5b612" Send ComAddParam To hoReq "label_file_type" "PDF" Send ComAddParam To hoReq "async" "false" Send ComAddHeader To hoReq "Authorization" "ShippoToken <API_TOKEN>" Get pvComObject of hoReq to vReq Get ComPostUrlEncoded Of hoHttp "https://api.goshippo.com/transactions" vReq To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJResp If (Not(IsComObjectCreated(hoJResp))) Begin Send CreateComObject of hoJResp End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess Set ComEmitCompact Of hoJResp To False Showln "Response Body:" Get ComEmit Of hoJResp To sTemp1 Showln sTemp1 Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End Send Destroy of hoResp // 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 Get ComStringOf Of hoJResp "object_state" To sObject_state Get ComStringOf Of hoJResp "status" To sStatus Get ComStringOf Of hoJResp "object_created" To sObject_created Get ComStringOf Of hoJResp "object_updated" To sObject_updated Get ComStringOf Of hoJResp "object_id" To sObject_id Get ComStringOf Of hoJResp "object_owner" To sObject_owner Get ComBoolOf Of hoJResp "test" To iTest Get ComStringOf Of hoJResp "rate" To sRate Get ComStringOf Of hoJResp "tracking_number" To sTracking_number Get ComStringOf Of hoJResp "tracking_status" To sTracking_status Get ComStringOf Of hoJResp "eta" To sEta Get ComStringOf Of hoJResp "tracking_url_provider" To sTracking_url_provider Get ComStringOf Of hoJResp "label_url" To sLabel_url Get ComStringOf Of hoJResp "commercial_invoice_url" To sCommercial_invoice_url Get ComStringOf Of hoJResp "order" To sOrder Get ComStringOf Of hoJResp "metadata" To sMetadata Get ComStringOf Of hoJResp "parcel" To sParcel Move 0 To i Get ComSizeOfArray Of hoJResp "messages" To iCount_i While (i < iCount_i) Set ComI Of hoJResp To i Move (i + 1) To i Loop Move 0 To i Get ComSizeOfArray Of hoJResp "billing.payments" To iCount_i While (i < iCount_i) Set ComI Of hoJResp To i Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.