Chilkat Online Tools

SQL Server / Zoho CRM REST APIs / Quotes

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}}"
    --       },
    --       "Contact_Name": {
    --         "id": "{{contact-id}}"
    --       },
    --       "Deal_Name": {
    --         "id": "{{deal-id}}"
    --       },
    --       "Account_Name": {
    --         "id": "{{account-name}}"
    --       },
    --       "Discount": 127.67,
    --       "Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
    --       "Shipping_State": "Shipping_State",
    --       "Tax": 127.67,
    --       "Valid_Till": "2018-01-25",
    --       "Billing_Country": "Billing_Country",
    --       "Team": "Team",
    --       "Carrier": "USPS",
    --       "Quote_Stage": "Delivered",
    --       "Billing_Street": "Billing_Street",
    --       "Adjustment": 127.67,
    --       "Terms_and_Conditions": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
    --       "Billing_Code": "Billing_Code",
    --       "Product_Details": [
    --         {
    --           "product": {
    --             "id": "1000000071967"
    --           },
    --           "quantity": 150,
    --           "Discount": 20,
    --           "product_description": "product_description",
    --           "Unit Price": 10,
    --           "line_tax": [
    --             {
    --               "percentage": 10.5,
    --               "name": "Sales Tax"
    --             },
    --             {
    --               "percentage": 6.5,
    --               "name": "Common Tax"
    --             }
    --           ]
    --         }
    --       ],
    --       "Subject": "Subject",
    --       "Shipping_City": "Shipping_City",
    --       "Shipping_Country": "Shipping_Country",
    --       "Shipping_Code": "Shipping_Code",
    --       "Billing_City": "Billing_City",
    --       "Billing_State": "Billing_State",
    --       "$line_tax": [
    --         {
    --           "percentage": 12.5,
    --           "name": "Sales Tax"
    --         },
    --         {
    --           "percentage": 8.5,
    --           "name": "Common Tax"
    --         }
    --       ],
    --       "Shipping_Street": "Shipping_Street"
    --     }
    --   ]
    -- }

    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].Contact_Name.id', '{{contact-id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Deal_Name.id', '{{deal-id}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Account_Name.id', '{{account-name}}'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Discount', '127.67'
    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, 'UpdateString', @success OUT, 'data[0].Shipping_State', 'Shipping_State'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Tax', '127.67'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Valid_Till', '2018-01-25'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Billing_Country', 'Billing_Country'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Team', 'Team'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Carrier', 'USPS'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Quote_Stage', 'Delivered'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Billing_Street', 'Billing_Street'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Adjustment', '127.67'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Terms_and_Conditions', 'Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Billing_Code', 'Billing_Code'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Product_Details[0].product.id', '1000000071967'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data[0].Product_Details[0].quantity', 150
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data[0].Product_Details[0].Discount', 20
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Product_Details[0].product_description', 'product_description'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data[0].Product_Details[0]."Unit Price"', 10
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Product_Details[0].line_tax[0].percentage', '10.5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Product_Details[0].line_tax[0].name', 'Sales Tax'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].Product_Details[0].line_tax[1].percentage', '6.5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Product_Details[0].line_tax[1].name', 'Common Tax'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Subject', 'Subject'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Shipping_City', 'Shipping_City'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Shipping_Country', 'Shipping_Country'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Shipping_Code', 'Shipping_Code'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Billing_City', 'Billing_City'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Billing_State', 'Billing_State'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].$line_tax[0].percentage', '12.5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].$line_tax[0].name', 'Sales Tax'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'data[0].$line_tax[1].percentage', '8.5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].$line_tax[1].name', 'Common Tax'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data[0].Shipping_Street', 'Shipping_Street'

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

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/crm/v2.1/Quotes', '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
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: {{authorization-token}}"
	-H "Content-Type: application/json"
	-d '{
	"data": [
		{
			"Owner": {
				"id": "{{user-id}}"
			},
			"Contact_Name": {
				"id": "{{contact-id}}"
			},
			"Deal_Name": {
				"id": "{{deal-id}}"
			},
			"Account_Name": {
				"id": "{{account-name}}"
			},
			"Discount": 127.67,
			"Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
			"Shipping_State": "Shipping_State",
			"Tax": 127.67,
			"Valid_Till": "2018-01-25",
			"Billing_Country": "Billing_Country",
			"Team": "Team",
			"Carrier": "USPS",
			"Quote_Stage": "Delivered",
			"Billing_Street": "Billing_Street",
			"Adjustment": 127.67,
			"Terms_and_Conditions": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
			"Billing_Code": "Billing_Code",
			"Product_Details": [
				{
					"product": {"id":"1000000071967"},
					"quantity": 150,
					"Discount": 20,
					"product_description": "product_description",
					"Unit Price": 10,
					"line_tax": [
						{
							"percentage": 10.5,
							"name": "Sales Tax"
						},
						{
							"percentage": 6.5,
							"name": "Common Tax"
						}
					]
				}
			],
			"Subject": "Subject",
			"Shipping_City": "Shipping_City",
			"Shipping_Country": "Shipping_Country",
			"Shipping_Code": "Shipping_Code",
			"Billing_City": "Billing_City",
			"Billing_State": "Billing_State",
			"$line_tax": [
				{
					"percentage": 12.5,
					"name": "Sales Tax"
				},
				{
					"percentage": 8.5,
					"name": "Common Tax"
				}
			],
			"Shipping_Street": "Shipping_Street"
		}
	]
}'
https://domain.com/crm/v2.1/Quotes

Postman Collection Item JSON

{
  "name": "Quotes",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "{{authorization-token}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"data\": [\n\t\t{\n\t\t\t\"Owner\": {\n\t\t\t\t\"id\": \"{{user-id}}\"\n\t\t\t},\n\t\t\t\"Contact_Name\": {\n\t\t\t\t\"id\": \"{{contact-id}}\"\n\t\t\t},\n\t\t\t\"Deal_Name\": {\n\t\t\t\t\"id\": \"{{deal-id}}\"\n\t\t\t},\n\t\t\t\"Account_Name\": {\n\t\t\t\t\"id\": \"{{account-name}}\"\n\t\t\t},\n\t\t\t\"Discount\": 127.67,\n\t\t\t\"Description\": \"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.\",\n\t\t\t\"Shipping_State\": \"Shipping_State\",\n\t\t\t\"Tax\": 127.67,\n\t\t\t\"Valid_Till\": \"2018-01-25\",\n\t\t\t\"Billing_Country\": \"Billing_Country\",\n\t\t\t\"Team\": \"Team\",\n\t\t\t\"Carrier\": \"USPS\",\n\t\t\t\"Quote_Stage\": \"Delivered\",\n\t\t\t\"Billing_Street\": \"Billing_Street\",\n\t\t\t\"Adjustment\": 127.67,\n\t\t\t\"Terms_and_Conditions\": \"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.\",\n\t\t\t\"Billing_Code\": \"Billing_Code\",\n\t\t\t\"Product_Details\": [\n\t\t\t\t{\n\t\t\t\t\t\"product\": {\"id\":\"1000000071967\"},\n\t\t\t\t\t\"quantity\": 150,\n\t\t\t\t\t\"Discount\": 20,\n\t\t\t\t\t\"product_description\": \"product_description\",\n\t\t\t\t\t\"Unit Price\": 10,\n\t\t\t\t\t\"line_tax\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"percentage\": 10.5,\n\t\t\t\t\t\t\t\"name\": \"Sales Tax\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"percentage\": 6.5,\n\t\t\t\t\t\t\t\"name\": \"Common Tax\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"Subject\": \"Subject\",\n\t\t\t\"Shipping_City\": \"Shipping_City\",\n\t\t\t\"Shipping_Country\": \"Shipping_Country\",\n\t\t\t\"Shipping_Code\": \"Shipping_Code\",\n\t\t\t\"Billing_City\": \"Billing_City\",\n\t\t\t\"Billing_State\": \"Billing_State\",\n\t\t\t\"$line_tax\": [\n\t\t\t\t{\n\t\t\t\t\t\"percentage\": 12.5,\n\t\t\t\t\t\"name\": \"Sales Tax\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"percentage\": 8.5,\n\t\t\t\t\t\"name\": \"Common Tax\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"Shipping_Street\": \"Shipping_Street\"\n\t\t}\n\t]\n}"
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/Quotes",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "Quotes"
      ]
    },
    "description": "To add new entities to a module."
  },
  "response": [
  ]
}