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 Label PurchaseDemonstrates how to create a shipping label in one API call through Shippo. For more information, see https://goshippo.com/docs/shipping-labels/
integer li_rc oleobject loo_Http integer li_Success oleobject loo_Json 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>" \ // -H "Content-Type: application/json" \ // -d '{ // "shipment": { // "address_from": { // "name": "Mr. Hippo", // "street1": "215 Clayton St.", // "city": "San Francisco", // "state": "CA", // "zip": "94117", // "country": "US", // "phone": "+1 555 341 9393", // "email": "support@goshippo.com" // }, // "address_to": { // "name": "Mrs. Hippo", // "street1": "965 Mission St.", // "city": "San Francisco", // "state": "CA", // "zip": "94105", // "country": "US", // "phone": "+1 555 341 9393", // "email": "support@goshippo.com" // }, // "parcels": [{ // "length": "5", // "width": "5", // "height": "5", // "distance_unit": "in", // "weight": "2", // "mass_unit": "lb" // }] // }, // "carrier_account": "b741b99f95e841639b54272834bc478c", // "servicelevel_token": "usps_priority" // }' // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "shipment": { // "address_from": { // "name": "Mr. Hippo", // "street1": "215 Clayton St.", // "city": "San Francisco", // "state": "CA", // "zip": "94117", // "country": "US", // "phone": "+1 555 341 9393", // "email": "support@goshippo.com" // }, // "address_to": { // "name": "Mrs. Hippo", // "street1": "965 Mission St.", // "city": "San Francisco", // "state": "CA", // "zip": "94105", // "country": "US", // "phone": "+1 555 341 9393", // "email": "support@goshippo.com" // }, // "parcels": [ // { // "length": "5", // "width": "5", // "height": "5", // "distance_unit": "in", // "weight": "2", // "mass_unit": "lb" // } // ] // }, // "carrier_account": "b741b99f95e841639b54272834bc478c", // "servicelevel_token": "usps_priority" // } loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateString("shipment.address_from.name","Mr. Hippo") loo_Json.UpdateString("shipment.address_from.street1","215 Clayton St.") loo_Json.UpdateString("shipment.address_from.city","San Francisco") loo_Json.UpdateString("shipment.address_from.state","CA") loo_Json.UpdateString("shipment.address_from.zip","94117") loo_Json.UpdateString("shipment.address_from.country","US") loo_Json.UpdateString("shipment.address_from.phone","+1 555 341 9393") loo_Json.UpdateString("shipment.address_from.email","support@goshippo.com") loo_Json.UpdateString("shipment.address_to.name","Mrs. Hippo") loo_Json.UpdateString("shipment.address_to.street1","965 Mission St.") loo_Json.UpdateString("shipment.address_to.city","San Francisco") loo_Json.UpdateString("shipment.address_to.state","CA") loo_Json.UpdateString("shipment.address_to.zip","94105") loo_Json.UpdateString("shipment.address_to.country","US") loo_Json.UpdateString("shipment.address_to.phone","+1 555 341 9393") loo_Json.UpdateString("shipment.address_to.email","support@goshippo.com") loo_Json.UpdateString("shipment.parcels[0].length","5") loo_Json.UpdateString("shipment.parcels[0].width","5") loo_Json.UpdateString("shipment.parcels[0].height","5") loo_Json.UpdateString("shipment.parcels[0].distance_unit","in") loo_Json.UpdateString("shipment.parcels[0].weight","2") loo_Json.UpdateString("shipment.parcels[0].mass_unit","lb") loo_Json.UpdateString("carrier_account","b741b99f95e841639b54272834bc478c") loo_Json.UpdateString("servicelevel_token","usps_priority") loo_Http.SetRequestHeader("Authorization","ShippoToken <API_Token>") loo_Http.SetRequestHeader("Content-Type","application/json") loo_Resp = loo_Http.PostJson3("https://api.goshippo.com/transactions/","application/json",loo_Json) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Json 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_Json 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_Json destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.