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 Create an OrderDemonstrates how to create an order with all the information about your order by sending a POST request to the orders endpoint. For more information, see https://goshippo.com/docs/orders/
-- 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/orders/ \ -- -H "Authorization: ShippoToken <API_Token>" \ -- -H "Content-Type: application/json" \ -- -d '{ -- "to_address": { -- "city": "San Francisco", -- "company": "Shippo", -- "country": "US", -- "email": "shippotle@goshippo.com", -- "name": "Mr Hippo", -- "phone": "15553419393", -- "state": "CA", -- "street1": "215 Clayton St.", -- "zip": "94117" -- }, -- "line_items": [ -- { -- "quantity": 1, -- "sku": "HM-123", -- "title": "Hippo Magazines", -- "total_price": "12.10", -- "currency": "USD", -- "weight": "0.40", -- "weight_unit": "lb" -- } -- ], -- "placed_at": "2016-09-23T01:28:12Z", -- "order_number": "#1068", -- "order_status": "PAID", -- "shipping_cost": "12.83", -- "shipping_cost_currency": "USD", -- "shipping_method": "USPS First Class Package", -- "subtotal_price": "12.10", -- "total_price": "24.93", -- "total_tax": "0.00", -- "currency": "USD", -- "weight": "0.40", -- "weight_unit": "lb" -- }' -- Use this online tool to generate code from sample JSON: -- Generate Code to Create JSON -- The following JSON is sent in the request body. -- { -- "to_address": { -- "city": "San Francisco", -- "company": "Shippo", -- "country": "US", -- "email": "shippotle@goshippo.com", -- "name": "Mr Hippo", -- "phone": "15553419393", -- "state": "CA", -- "street1": "215 Clayton St.", -- "zip": "94117" -- }, -- "line_items": [ -- { -- "quantity": 1, -- "sku": "HM-123", -- "title": "Hippo Magazines", -- "total_price": "12.10", -- "currency": "USD", -- "weight": "0.40", -- "weight_unit": "lb" -- } -- ], -- "placed_at": "2016-09-23T01:28:12Z", -- "order_number": "#1068", -- "order_status": "PAID", -- "shipping_cost": "12.83", -- "shipping_cost_currency": "USD", -- "shipping_method": "USPS First Class Package", -- "subtotal_price": "12.10", -- "total_price": "24.93", -- "total_tax": "0.00", -- "currency": "USD", -- "weight": "0.40", -- "weight_unit": "lb" -- } 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, 'to_address.city', 'San Francisco' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.company', 'Shippo' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.country', 'US' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.email', 'shippotle@goshippo.com' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.name', 'Mr Hippo' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.phone', '15553419393' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.state', 'CA' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.street1', '215 Clayton St.' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_address.zip', '94117' EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'line_items[0].quantity', 1 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].sku', 'HM-123' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].title', 'Hippo Magazines' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].total_price', '12.10' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].currency', 'USD' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].weight', '0.40' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'line_items[0].weight_unit', 'lb' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'placed_at', '2016-09-23T01:28:12Z' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order_number', '#1068' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order_status', 'PAID' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipping_cost', '12.83' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipping_cost_currency', 'USD' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipping_method', 'USPS First Class Package' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'subtotal_price', '12.10' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'total_price', '24.93' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'total_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'currency', 'USD' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'weight', '0.40' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'weight_unit', 'lb' 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/orders/', '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) -- {} -- Sample code for parsing the JSON response... -- Use the following online tool to generate parsing code from sample JSON: -- Generate Parsing Code from JSON 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.