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) Add order to a ShippingEasy accountAdds an order to a ShippingEasy account (calls the ShippingEasy REST API).
-- 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) DECLARE @sTmp1 nvarchar(4000) -- This requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @success int -- First create the JSON for the order. -- See https://shippingeasy.readme.io/v1.0/docs/creating-a-signature -- for sample JSON. -- You may use the online tool at https://tools.chilkat.io/Default.cshtml to -- generate the following code by pasting sample JSON into the tool. DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.external_order_identifier', 'ABC-100' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.ordered_at', '2014-01-16 14:37:56 -0600' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.order_status', 'awaiting_shipment' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.subtotal_including_tax', '10.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.total_including_tax', '10.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.total_excluding_tax', '10.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.discount_amount', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.coupon_discount', '1.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.subtotal_including_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.subtotal_excluding_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.subtotal_excluding_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.subtotal_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.total_tax', '0' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.base_shipping_cost', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.shipping_cost_including_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.shipping_cost_excluding_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.shipping_cost_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.base_handling_cost', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.handling_cost_excluding_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.handling_cost_including_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.handling_cost_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.base_wrapping_cost', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.wrapping_cost_excluding_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.wrapping_cost_including_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.wrapping_cost_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.notes', 'Please send promptly.' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_company', 'Acme Inc.' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_first_name', 'Fred' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_last_name', 'Jones' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_address', '1234 Street' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_address2', 'Suite 100' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_city', 'Austin' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_state', 'TX' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_postal_code', '78701' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_country', 'USA' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_phone_number', '512-123-1234' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.billing_email', 'test@test.com' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].first_name', 'Colin' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].last_name', 'Homenick' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].company', 'Wintheiser-Hickle' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].email', 'charles.crona@okeefe.org' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].phone_number', '637-481-6505' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].residential', 'true' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].address', '21937 Adelbert Springs' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].address2', '' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].province', '' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].state', 'CT' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].city', 'Terryfurt' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].postal_code', '93322' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].postal_code_plus_4', '1234' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].country', 'Andorra' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].shipping_method', 'Ground' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].base_cost', '10.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].cost_excluding_tax', '10.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].cost_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].base_handling_cost', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].handling_cost_excluding_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].handling_cost_including_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].handling_cost_tax', '0.00' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].shipping_zone_id', '123' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].shipping_zone_name', 'XYZ' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].items_total', '1' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].items_shipped', '0' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].item_name', 'Pencil Holder' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].sku', '9876543' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].bin_picking_number', '7' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].unit_price', '1.30' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].total_excluding_tax', '1.30' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].weight_in_ounces', '10' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].product_options.pa_size', 'large' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].product_options.Colour', 'Blue' EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].line_items[0].quantity', '1' -- Replace these values with your actual apiKey and apiSecret. -- (These are not valid values..) DECLARE @storeApiKey nvarchar(4000) SELECT @storeApiKey = '569dc30d267f2c4d1f85f9920b2bf9f4' DECLARE @apiKey nvarchar(4000) SELECT @apiKey = 'f9a7c8ebdfd34beaf260d9b0296c7059' DECLARE @apiSecret nvarchar(4000) SELECT @apiSecret = 'd3e9f8737d7196b1271a725f89e2156672bc1d900a25e6e0c1364e2f7a20f605' -- Our request will be sent to: -- https://app.shippingeasy.com/api/stores/:store_api_key/orders -- The path part of this request is: /api/stores/:store_api_key/orders -- See https://shippingeasy.readme.io/v1.0/docs/authentication-signing-requests DECLARE @sbSigStr int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbSigStr OUT EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, 'POST&/api/stores/' EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, @storeApiKey EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, '/orders&' EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, 'api_key=' EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, @apiKey EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, '&api_timestamp=' DECLARE @dt int -- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dt OUT EXEC sp_OAMethod @dt, 'SetFromCurrentSystemTime', @success OUT EXEC sp_OAMethod @dt, 'GetAsUnixTimeStr', @sTmp0 OUT, 0 EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, @sTmp0 EXEC sp_OAMethod @sbSigStr, 'Append', @success OUT, '&' EXEC sp_OASetProperty @json, 'EmitCompact', 1 EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbSigStr -- Calculate the HMAC-SHA256 of the API Signature String using the API Secret as the HMAC key. DECLARE @crypt int -- Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT EXEC sp_OASetProperty @crypt, 'MacAlgorithm', 'hmac' EXEC sp_OASetProperty @crypt, 'EncodingMode', 'hex' EXEC sp_OAMethod @crypt, 'SetMacKeyString', @success OUT, @apiSecret EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha256' DECLARE @sbSignature int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbSignature OUT EXEC sp_OAMethod @sbSigStr, 'GetAsString', @sTmp1 OUT EXEC sp_OAMethod @crypt, 'MacStringENC', @sTmp0 OUT, @sTmp1 EXEC sp_OAMethod @sbSignature, 'Append', @success OUT, @sTmp0 EXEC sp_OAMethod @sbSignature, 'ToLowercase', @success OUT 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.shippingeasy.com/api/stores/' EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, @storeApiKey EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, '/orders?' EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, 'api_key=' EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, @apiKey EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, '&api_timestamp=' EXEC sp_OAMethod @dt, 'GetAsUnixTimeStr', @sTmp0 OUT, 0 EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, @sTmp0 EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, '&api_signature=' EXEC sp_OAMethod @sbSignature, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, @sTmp0 -- Send a POST equivalent the following curl request: -- curl -H "Content-Type: application/json" --data @body.json "https://app.shippingeasy.com/api/stores/27aa472e16faa83dd13b7758d31974ed/orders? -- api_key=f9a7c8ebdfd34beaf260d9b0296c7059& -- api_timestamp=1401803554& -- api_signature=c65f43beed46e581939898a78acd10064cfa146845e97885ec02124d7ad648e4" 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_OASetProperty @http, 'SessionLogFilename', 'qa_output/shippingEasy.txt' DECLARE @resp int EXEC sp_OAMethod @sbUrl, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @json, 'Emit', @sTmp1 OUT EXEC sp_OAMethod @http, 'PostJson2', @resp OUT, @sTmp0, 'application/json', @sTmp1 EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @json EXEC @hr = sp_OADestroy @sbSigStr EXEC @hr = sp_OADestroy @dt EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @sbSignature EXEC @hr = sp_OADestroy @sbUrl EXEC @hr = sp_OADestroy @http RETURN END EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT 'response status code = ' + @iTmp0 PRINT 'response body:' EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @json EXEC @hr = sp_OADestroy @sbSigStr EXEC @hr = sp_OADestroy @dt EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @sbSignature EXEC @hr = sp_OADestroy @sbUrl EXEC @hr = sp_OADestroy @http END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.