Chilkat Online Tools

SQL Server / ShippingEasy API / Create Order

Back to Collection Items

-- 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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "order": {
    --     "external_order_identifier": "ABC-105",
    --     "ordered_at": "2014-01-16 14:37:56 -0600",
    --     "order_status": "awaiting_shipment",
    --     "subtotal_including_tax": "10.00",
    --     "total_including_tax": "10.00",
    --     "total_excluding_tax": "10.00",
    --     "discount_amount": "0.00",
    --     "coupon_discount": "1.00",
    --     "subtotal_excluding_tax": "0.00",
    --     "subtotal_tax": "0.00",
    --     "total_tax": "0",
    --     "base_shipping_cost": "0.00",
    --     "shipping_cost_including_tax": "0.00",
    --     "shipping_cost_excluding_tax": "0.00",
    --     "shipping_cost_tax": "0.00",
    --     "base_handling_cost": "0.00",
    --     "handling_cost_excluding_tax": "0.00",
    --     "handling_cost_including_tax": "0.00",
    --     "handling_cost_tax": "0.00",
    --     "base_wrapping_cost": "0.00",
    --     "wrapping_cost_excluding_tax": "0.00",
    --     "wrapping_cost_including_tax": "0.00",
    --     "wrapping_cost_tax": "0.00",
    --     "notes": "Please send promptly.",
    --     "billing_company": "Acme Inc.",
    --     "billing_first_name": "Fred",
    --     "billing_last_name": "Jones",
    --     "billing_address": "1234 Street",
    --     "billing_address2": "Suite 100",
    --     "billing_city": "Austin",
    --     "billing_state": "TX",
    --     "billing_postal_code": "78701",
    --     "billing_country": "USA",
    --     "billing_phone_number": "512-123-1234",
    --     "billing_email": "test@test.com",
    --     "recipients": [
    --       {
    --         "first_name": "Jack",
    --         "last_name": "Ship",
    --         "company": "ShippingEasy",
    --         "email": "jack@shippingeasy.com",
    --         "phone_number": "855-202-2275",
    --         "residential": "true",
    --         "address": "3700 N Capital of Texas Hwy Ste 550",
    --         "address2": "",
    --         "province": "",
    --         "state": "TX",
    --         "city": "Austin",
    --         "postal_code": "78746",
    --         "postal_code_plus_4": "1234",
    --         "country": "United States",
    --         "shipping_method": "Ground",
    --         "base_cost": "10.00",
    --         "cost_excluding_tax": "10.00",
    --         "cost_tax": "0.00",
    --         "base_handling_cost": "0.00",
    --         "handling_cost_excluding_tax": "0.00",
    --         "handling_cost_including_tax": "0.00",
    --         "handling_cost_tax": "0.00",
    --         "shipping_zone_id": "123",
    --         "shipping_zone_name": "XYZ",
    --         "items_total": "1",
    --         "items_shipped": "0",
    --         "line_items": [
    --           {
    --             "item_name": "Pencil Holder",
    --             "sku": "9876543",
    --             "bin_picking_number": "7",
    --             "unit_price": "1.30",
    --             "total_excluding_tax": "1.30",
    --             "weight_in_ounces": "10",
    --             "product_options": {
    --               "pa_size": "large",
    --               "Colour": "Blue"
    --             },
    --             "quantity": "1"
    --           }
    --         ]
    --       }
    --     ]
    --   }
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.external_order_identifier', 'ABC-105'
    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_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', 'Jack'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].last_name', 'Ship'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].company', 'ShippingEasy'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].email', 'jack@shippingeasy.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].phone_number', '855-202-2275'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].residential', 'true'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].address', '3700 N Capital of Texas Hwy Ste 550'
    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', 'TX'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].city', 'Austin'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'order.recipients[0].postal_code', '78746'
    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', 'United States'
    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'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'Key}}', '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

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-d '{
    "order": {
        "external_order_identifier": "ABC-105",
        "ordered_at": "2014-01-16 14:37:56 -0600",
        "order_status": "awaiting_shipment",
        "subtotal_including_tax": "10.00",
        "total_including_tax": "10.00",
        "total_excluding_tax": "10.00",
        "discount_amount": "0.00",
        "coupon_discount": "1.00",
        "subtotal_excluding_tax": "0.00",
        "subtotal_tax": "0.00",
        "total_tax": "0",
        "base_shipping_cost": "0.00",
        "shipping_cost_including_tax": "0.00",
        "shipping_cost_excluding_tax": "0.00",
        "shipping_cost_tax": "0.00",
        "base_handling_cost": "0.00",
        "handling_cost_excluding_tax": "0.00",
        "handling_cost_including_tax": "0.00",
        "handling_cost_tax": "0.00",
        "base_wrapping_cost": "0.00",
        "wrapping_cost_excluding_tax": "0.00",
        "wrapping_cost_including_tax": "0.00",
        "wrapping_cost_tax": "0.00",
        "notes": "Please send promptly.",
        "billing_company": "Acme Inc.",
        "billing_first_name": "Fred",
        "billing_last_name": "Jones",
        "billing_address": "1234 Street",
        "billing_address2": "Suite 100",
        "billing_city": "Austin",
        "billing_state": "TX",
        "billing_postal_code": "78701",
        "billing_country": "USA",
        "billing_phone_number": "512-123-1234",
        "billing_email": "test@test.com",
        "recipients": [
            {
                "first_name": "Jack",
                "last_name": "Ship",
                "company": "ShippingEasy",
                "email": "jack@shippingeasy.com",
                "phone_number": "855-202-2275",
                "residential": "true",
                "address": "3700 N Capital of Texas Hwy Ste 550",
                "address2": "",
                "province": "",
                "state": "TX",
                "city": "Austin",
                "postal_code": "78746",
                "postal_code_plus_4": "1234",
                "country": "United States",
                "shipping_method": "Ground",
                "base_cost": "10.00",
                "cost_excluding_tax": "10.00",
                "cost_tax": "0.00",
                "base_handling_cost": "0.00",
                "handling_cost_excluding_tax": "0.00",
                "handling_cost_including_tax": "0.00",
                "handling_cost_tax": "0.00",
                "shipping_zone_id": "123",
                "shipping_zone_name": "XYZ",
                "items_total": "1",
                "items_shipped": "0",
                "line_items": [
                    {
                        "item_name": "Pencil Holder",
                        "sku": "9876543",
                        "bin_picking_number": "7",
                        "unit_price": "1.30",
                        "total_excluding_tax": "1.30",
                        "weight_in_ounces": "10",
                        "product_options": {
                            "pa_size": "large",
                            "Colour": "Blue"
                        },
                        "quantity": "1"
                    }
                ]
            }
        ]
    }
}'
https://app.shippingeasy.com/api/stores/{{Store API Key}}/orders?api_signature={{api_signature}}&api_timestamp={{api_timestamp}}&api_key={{API Key}}

Postman Collection Item JSON

{
  "name": "Create Order",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// calculate timestamp",
          "const timestamp = parseInt(Date.now() / 1000);",
          "console.log(\"timestamp: \" + timestamp);",
          "pm.variables.set(\"api_timestamp\", timestamp);",
          "",
          "// Set your API key and API secret as Postman environment variables, your key and secret are available at https://app.shippingeasy.com/settings/api_credentials",
          "const apiKey = pm.environment.get(\"API Key\");",
          "const apiSecret = pm.environment.get(\"API Secret\");",
          "const storeApiKey = pm.environment.get(\"Store API Key\");",
          "",
          "// build signature string - https://shippingeasy.readme.io/docs/authentication-signing-requests#how-to-calculate-a-signature",
          "const signatureString = pm.request.method + \"&\" +",
          "  \"/api/stores/\" + storeApiKey + \"/orders&\" +",
          "  \"api_key=\" + apiKey + \"&\" +",
          "  \"api_timestamp=\" + timestamp + \"&\" +",
          "  pm.request.body.toString();",
          "console.log(\"signature string: \" + signatureString);",
          "",
          "// generate signature",
          "const apiSignature = CryptoJS.HmacSHA256(signatureString, apiSecret).toString(CryptoJS.enc.Hex);",
          "console.log(\"api request signature: \" + apiSignature);",
          "pm.variables.set(\"api_signature\", apiSignature);"
        ]
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"order\": {\n        \"external_order_identifier\": \"ABC-105\",\n        \"ordered_at\": \"2014-01-16 14:37:56 -0600\",\n        \"order_status\": \"awaiting_shipment\",\n        \"subtotal_including_tax\": \"10.00\",\n        \"total_including_tax\": \"10.00\",\n        \"total_excluding_tax\": \"10.00\",\n        \"discount_amount\": \"0.00\",\n        \"coupon_discount\": \"1.00\",\n        \"subtotal_excluding_tax\": \"0.00\",\n        \"subtotal_tax\": \"0.00\",\n        \"total_tax\": \"0\",\n        \"base_shipping_cost\": \"0.00\",\n        \"shipping_cost_including_tax\": \"0.00\",\n        \"shipping_cost_excluding_tax\": \"0.00\",\n        \"shipping_cost_tax\": \"0.00\",\n        \"base_handling_cost\": \"0.00\",\n        \"handling_cost_excluding_tax\": \"0.00\",\n        \"handling_cost_including_tax\": \"0.00\",\n        \"handling_cost_tax\": \"0.00\",\n        \"base_wrapping_cost\": \"0.00\",\n        \"wrapping_cost_excluding_tax\": \"0.00\",\n        \"wrapping_cost_including_tax\": \"0.00\",\n        \"wrapping_cost_tax\": \"0.00\",\n        \"notes\": \"Please send promptly.\",\n        \"billing_company\": \"Acme Inc.\",\n        \"billing_first_name\": \"Fred\",\n        \"billing_last_name\": \"Jones\",\n        \"billing_address\": \"1234 Street\",\n        \"billing_address2\": \"Suite 100\",\n        \"billing_city\": \"Austin\",\n        \"billing_state\": \"TX\",\n        \"billing_postal_code\": \"78701\",\n        \"billing_country\": \"USA\",\n        \"billing_phone_number\": \"512-123-1234\",\n        \"billing_email\": \"test@test.com\",\n        \"recipients\": [\n            {\n                \"first_name\": \"Jack\",\n                \"last_name\": \"Ship\",\n                \"company\": \"ShippingEasy\",\n                \"email\": \"jack@shippingeasy.com\",\n                \"phone_number\": \"855-202-2275\",\n                \"residential\": \"true\",\n                \"address\": \"3700 N Capital of Texas Hwy Ste 550\",\n                \"address2\": \"\",\n                \"province\": \"\",\n                \"state\": \"TX\",\n                \"city\": \"Austin\",\n                \"postal_code\": \"78746\",\n                \"postal_code_plus_4\": \"1234\",\n                \"country\": \"United States\",\n                \"shipping_method\": \"Ground\",\n                \"base_cost\": \"10.00\",\n                \"cost_excluding_tax\": \"10.00\",\n                \"cost_tax\": \"0.00\",\n                \"base_handling_cost\": \"0.00\",\n                \"handling_cost_excluding_tax\": \"0.00\",\n                \"handling_cost_including_tax\": \"0.00\",\n                \"handling_cost_tax\": \"0.00\",\n                \"shipping_zone_id\": \"123\",\n                \"shipping_zone_name\": \"XYZ\",\n                \"items_total\": \"1\",\n                \"items_shipped\": \"0\",\n                \"line_items\": [\n                    {\n                        \"item_name\": \"Pencil Holder\",\n                        \"sku\": \"9876543\",\n                        \"bin_picking_number\": \"7\",\n                        \"unit_price\": \"1.30\",\n                        \"total_excluding_tax\": \"1.30\",\n                        \"weight_in_ounces\": \"10\",\n                        \"product_options\": {\n                            \"pa_size\": \"large\",\n                            \"Colour\": \"Blue\"\n                        },\n                        \"quantity\": \"1\"\n                    }\n                ]\n            }\n        ]\n    }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "app.shippingeasy.com/api/stores/{{Store API Key}}/orders?api_signature={{api_signature}}&api_timestamp={{api_timestamp}}&api_key={{API Key}}",
      "host": [
        "app",
        "shippingeasy",
        "com"
      ],
      "path": [
        "api",
        "stores",
        "{{Store API Key}}",
        "orders"
      ],
      "query": [
        {
          "key": "api_signature",
          "value": "{{api_signature}}"
        },
        {
          "key": "api_timestamp",
          "value": "{{api_timestamp}}"
        },
        {
          "key": "api_key",
          "value": "{{API Key}}"
        }
      ]
    },
    "description": "Create an order in ShippingEasy."
  },
  "response": [
  ]
}