Chilkat Online Tools

SQL Server / Zoho CRM REST APIs / Products

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
    -- 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

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

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

    -- {
    --   "data": [
    --     {
    --       "Owner": {
    --         "id": "{{user-id}}"
    --       },
    --       "Handler": {
    --         "id": "{{user-id}}"
    --       },
    --       "Vendor_Name": {
    --         "id": "{{vendor-id}}"
    --       },
    --       "Product_Category": "Software",
    --       "Qty_in_Demand": 1237.89,
    --       "Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
    --       "Commission_Rate": 1237.67,
    --       "Product_Name": "Product_Name",
    --       "Quantity_In_Stock": 12792,
    --       "Sales_Start_Date": "2018-01-25",
    --       "Tax": [
    --         "Sales Tax"
    --       ],
    --       "Support_Start_Date": "2018-01-25",
    --       "Product_Active": true,
    --       "Usage_Unit": "Caton",
    --       "Product_Code": "Product_Code",
    --       "Qty_Ordered": 1237.89,
    --       "Manufacturer": "LexPon Inc.",
    --       "Qty_in_Stock": 1237.89,
    --       "Support_Expiry_Date": "2018-01-25",
    --       "Sales_End_Date": "2018-01-25",
    --       "Unit_Price": 1237.67,
    --       "Taxable": true,
    --       "Reorder_Level": 1237.89
    --     }
    --   ]
    -- }

    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, 'data[0].Owner.id', '{{user-id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Handler.id', '{{user-id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Vendor_Name.id', '{{vendor-id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Product_Category', 'Software'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Qty_in_Demand', '1237.89'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Description', 'Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Commission_Rate', '1237.67'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Product_Name', 'Product_Name'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data[0].Quantity_In_Stock', 12792
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Sales_Start_Date', '2018-01-25'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Tax[0]', 'Sales Tax'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Support_Start_Date', '2018-01-25'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'data[0].Product_Active', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Usage_Unit', 'Caton'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Product_Code', 'Product_Code'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Qty_Ordered', '1237.89'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Manufacturer', 'LexPon Inc.'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Qty_in_Stock', '1237.89'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Support_Expiry_Date', '2018-01-25'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Sales_End_Date', '2018-01-25'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Unit_Price', '1237.67'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'data[0].Taxable', 1
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Reorder_Level', '1237.89'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{authorization-token}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @sbRequestBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://domain.com/crm/v2.1/Products/{{record-id}}', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    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
        EXEC @hr = sp_OADestroy @sbRequestBody
        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
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: {{authorization-token}}"
	-H "Content-Type: application/json"
	-d '{
  "data": [
    {
      "Owner": {
        "id": "{{user-id}}"
      },
      "Handler": {
        "id": "{{user-id}}"
      },
      "Vendor_Name": {
        "id": "{{vendor-id}}"
      },
      "Product_Category": "Software",
      "Qty_in_Demand": 1237.89,
      "Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
      "Commission_Rate": 1237.67,
      "Product_Name": "Product_Name",
      "Quantity_In_Stock": 12792,
      "Sales_Start_Date": "2018-01-25",
      "Tax": [
        "Sales Tax"
      ],
      "Support_Start_Date": "2018-01-25",
      "Product_Active": true,
      "Usage_Unit": "Caton",
      "Product_Code": "Product_Code",
      "Qty_Ordered": 1237.89,
      "Manufacturer": "LexPon Inc.",
      "Qty_in_Stock": 1237.89,
      "Support_Expiry_Date": "2018-01-25",
      "Sales_End_Date": "2018-01-25",
      "Unit_Price": 1237.67,
      "Taxable": true,
      "Reorder_Level": 1237.89
    }
  ]
}'
https://domain.com/crm/v2.1/Products/{{record-id}}

Postman Collection Item JSON

{
  "name": "Products",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Authorization",
        "value": "{{authorization-token}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": [\n    {\n      \"Owner\": {\n        \"id\": \"{{user-id}}\"\n      },\n      \"Handler\": {\n        \"id\": \"{{user-id}}\"\n      },\n      \"Vendor_Name\": {\n        \"id\": \"{{vendor-id}}\"\n      },\n      \"Product_Category\": \"Software\",\n      \"Qty_in_Demand\": 1237.89,\n      \"Description\": \"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.\",\n      \"Commission_Rate\": 1237.67,\n      \"Product_Name\": \"Product_Name\",\n      \"Quantity_In_Stock\": 12792,\n      \"Sales_Start_Date\": \"2018-01-25\",\n      \"Tax\": [\n        \"Sales Tax\"\n      ],\n      \"Support_Start_Date\": \"2018-01-25\",\n      \"Product_Active\": true,\n      \"Usage_Unit\": \"Caton\",\n      \"Product_Code\": \"Product_Code\",\n      \"Qty_Ordered\": 1237.89,\n      \"Manufacturer\": \"LexPon Inc.\",\n      \"Qty_in_Stock\": 1237.89,\n      \"Support_Expiry_Date\": \"2018-01-25\",\n      \"Sales_End_Date\": \"2018-01-25\",\n      \"Unit_Price\": 1237.67,\n      \"Taxable\": true,\n      \"Reorder_Level\": 1237.89\n    }\n  ]\n}"
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/Products/{{record-id}}",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "Products",
        "{{record-id}}"
      ]
    },
    "description": "To update existing entities in the module."
  },
  "response": [
  ]
}