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
(SQL Server) 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/
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example assumes the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- 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 DECLARE @req int -- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT EXEC sp_OASetProperty @req, 'HttpVerb', 'POST' EXEC sp_OASetProperty @req, 'Path', '/transactions' EXEC sp_OASetProperty @req, 'ContentType', 'application/x-www-form-urlencoded' EXEC sp_OAMethod @req, 'AddParam', NULL, 'rate', 'ec6143e746094bcab1bdc4c17600dabf' EXEC sp_OAMethod @req, 'AddParam', NULL, 'label_file_type', 'PDF' EXEC sp_OAMethod @req, 'AddParam', NULL, 'async', 'false' EXEC sp_OAMethod @req, 'AddHeader', NULL, 'Authorization', 'ShippoToken <API_TOKEN>' DECLARE @resp int EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://api.goshippo.com/transactions', @req EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req RETURN END DECLARE @sbResponseBody int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody DECLARE @jResp int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody EXEC sp_OASetProperty @jResp, 'EmitCompact', 0 PRINT 'Response Body:' EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT PRINT @sTmp0 DECLARE @respStatusCode int EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT PRINT 'Response Status Code = ' + @respStatusCode IF @respStatusCode >= 400 BEGIN PRINT 'Response Header:' EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT PRINT @sTmp0 PRINT 'Failed.' EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp RETURN END EXEC @hr = sp_OADestroy @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 DECLARE @object_state nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @object_state OUT, 'object_state' DECLARE @status nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status' DECLARE @object_created nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @object_created OUT, 'object_created' DECLARE @object_updated nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @object_updated OUT, 'object_updated' DECLARE @object_id nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @object_id OUT, 'object_id' DECLARE @object_owner nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @object_owner OUT, 'object_owner' DECLARE @was_test int EXEC sp_OAMethod @jResp, 'BoolOf', @was_test OUT, 'was_test' DECLARE @rateObject_id nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateObject_id OUT, 'rate.object_id' DECLARE @rateAmount nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateAmount OUT, 'rate.amount' DECLARE @rateCurrency nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateCurrency OUT, 'rate.currency' DECLARE @rateAmount_local nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateAmount_local OUT, 'rate.amount_local' DECLARE @rateCurrency_local nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateCurrency_local OUT, 'rate.currency_local' DECLARE @rateProvider nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateProvider OUT, 'rate.provider' DECLARE @rateServicelevel_name nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateServicelevel_name OUT, 'rate.servicelevel_name' DECLARE @rateServicelevel_token nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateServicelevel_token OUT, 'rate.servicelevel_token' DECLARE @rateCarrier_account nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @rateCarrier_account OUT, 'rate.carrier_account' DECLARE @tracking_number nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @tracking_number OUT, 'tracking_number' DECLARE @tracking_statusObject_created nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusObject_created OUT, 'tracking_status.object_created' DECLARE @tracking_statusObject_id nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusObject_id OUT, 'tracking_status.object_id' DECLARE @tracking_statusStatus nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusStatus OUT, 'tracking_status.status' DECLARE @tracking_statusStatus_details nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusStatus_details OUT, 'tracking_status.status_details' DECLARE @tracking_statusStatus_date nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusStatus_date OUT, 'tracking_status.status_date' DECLARE @tracking_url_provider nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @tracking_url_provider OUT, 'tracking_url_provider' DECLARE @eta nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @eta OUT, 'eta' DECLARE @label_url nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @label_url OUT, 'label_url' DECLARE @commercial_invoice_url nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @commercial_invoice_url OUT, 'commercial_invoice_url' DECLARE @metadata nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @metadata OUT, 'metadata' DECLARE @i int SELECT @i = 0 DECLARE @count_i int EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'messages' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @jResp, 'I', @i SELECT @i = @i + 1 END EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @req EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.