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 Label PurchaseDemonstrates how to create a shipping label in one API call through Shippo. For more information, see https://goshippo.com/docs/shipping-labels/
-- 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>" \ -- -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" -- } DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.name', 'Mr. Hippo' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.street1', '215 Clayton St.' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.city', 'San Francisco' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.state', 'CA' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.zip', '94117' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.country', 'US' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.phone', '+1 555 341 9393' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_from.email', 'support@goshippo.com' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.name', 'Mrs. Hippo' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.street1', '965 Mission St.' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.city', 'San Francisco' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.state', 'CA' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.zip', '94105' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.country', 'US' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.phone', '+1 555 341 9393' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.address_to.email', 'support@goshippo.com' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.parcels[0].length', '5' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.parcels[0].width', '5' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.parcels[0].height', '5' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.parcels[0].distance_unit', 'in' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.parcels[0].weight', '2' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment.parcels[0].mass_unit', 'lb' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'carrier_account', 'b741b99f95e841639b54272834bc478c' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'servicelevel_token', 'usps_priority' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', 'ShippoToken <API_Token>' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json' DECLARE @resp int EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.goshippo.com/transactions/', 'application/json', @json 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 @json 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 @json 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 @json EXEC @hr = sp_OADestroy @sbResponseBody EXEC @hr = sp_OADestroy @jResp END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.