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) Ecwid - Create OrderSee more Ecwid ExamplesCreate a new order in an Ecwid store. This can be useful for storefronts with a custom checkout process or manually creating orders for sales made earlier. For more information, see https://api-docs.ecwid.com/reference/orders#create-an-order
-- 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. -- Create and send the following HTTP request: -- Load the access token previously obtained in Ecwid Get Access Token DECLARE @jsonToken int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/ecwid.json' DECLARE @sbUrl int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbUrl OUT EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, 'https://app.ecwid.com/api/v3/4870020/orders?token=' EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'access_token' EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, @sTmp0 -- POST /api/v3/4870020/orders?token=1234567890qwqeertt HTTP/1.1 -- Host: app.ecwid.com -- Content-Type: application/json;charset=utf-8 -- Cache-Control: no-cache -- -- { -- "subtotal": 30, -- "total": 40, -- "email": "example@example.com", -- "paymentMethod": "Phone order", -- "tax": 0, -- "paymentStatus": "PAID", -- "customerTaxExempt": false, -- "customerTaxId": "", -- "customerTaxIdValid": false, -- "reversedTaxApplied": false, -- "fulfillmentStatus": "AWAITING_PROCESSING", -- "createDate": "2015-09-20 19:59:43 +0000", -- "items": [ -- { -- "price": 15, -- "weight": 0.32, -- "sku": "00004", -- "quantity": 2, -- "name": "Cherry" -- } -- ], -- "billingPerson": { -- "name": "Eugene K", -- "companyName": "Hedgehog and Bucket", -- "street": "My Street", -- "city": "San Diego", -- "countryCode": "US", -- "postalCode": "90002", -- "stateOrProvinceCode": "CA", -- "phone": "123141321" -- }, -- "shippingPerson": { -- "name": "Eugene K", -- "companyName": "Hedgehog and Bucket", -- "street": "My Street", -- "city": "San Diego", -- "countryCode": "US", -- "postalCode": "90002", -- "stateOrProvinceCode": "CA", -- "phone": "123141321" -- }, -- "shippingOption": { -- "shippingMethodName": "Fast Delivery", -- "shippingRate": 10, -- "isPickup": false, -- "fulfilmentType": "DELIVERY" -- }, -- "hidden": false, -- "privateAdminNotes": "Must be delivered till Sunday.", -- "acceptMarketing": false, -- "disableAllCustomerNotifications": true, -- "externalFulfillment": true, -- "externalOrderId": "2", -- "pricesIncludeTax": false -- } DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Cache-Control', 'no-cache' 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, 'UpdateInt', @success OUT, 'subtotal', 30 EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'total', 40 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'email', 'example@example.com' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'paymentMethod', 'Phone order' EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'tax', 0 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'paymentStatus', 'PAID' EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'customerTaxExempt', 0 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'customerTaxId', '' EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'customerTaxIdValid', 0 EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'reversedTaxApplied', 0 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'fulfillmentStatus', 'AWAITING_PROCESSING' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'createDate', '2015-09-20 19:59:43 +0000' EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].price', 15 EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].weight', '0.32' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sku', '00004' EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].quantity', 2 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].name', 'Cherry' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.name', 'Eugene K' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.companyName', 'Hedgehog and Bucket' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.street', 'My Street' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.city', 'San Diego' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.countryCode', 'US' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.postalCode', '90002' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.stateOrProvinceCode', 'CA' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'billingPerson.phone', '123141321' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.name', 'Eugene K' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.companyName', 'Hedgehog and Bucket' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.street', 'My Street' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.city', 'San Diego' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.countryCode', 'US' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.postalCode', '90002' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.stateOrProvinceCode', 'CA' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingPerson.phone', '123141321' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingOption.shippingMethodName', 'Fast Delivery' EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'shippingOption.shippingRate', 10 EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'shippingOption.isPickup', 0 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shippingOption.fulfilmentType', 'DELIVERY' EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'hidden', 0 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'privateAdminNotes', 'Must be delivered till Sunday.' EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'acceptMarketing', 0 EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'disableAllCustomerNotifications', 1 EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'externalFulfillment', 1 EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'externalOrderId', '2' EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'pricesIncludeTax', 0 DECLARE @resp int EXEC sp_OAMethod @sbUrl, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, @sTmp0, 'application/json', @json EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @sbUrl EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @json RETURN END EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT 'Response status code = ' + @iTmp0 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 -- Sample JSON response: -- (Sample code for parsing the JSON response is shown below) -- { -- "id": 20, -- "orderid": "XJ12H" -- } -- 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 @id int EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'id' DECLARE @orderid nvarchar(4000) EXEC sp_OAMethod @jResp, 'StringOf', @orderid OUT, 'orderid' EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @sbUrl 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.