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 XML: Generate Code to Create XML
-- The following XML is sent in the request body.
-- <?xml version="1.0" encoding="UTF-8"?>
-- <contract>
-- <name>Test API Contract 159753</name>
-- <number>159753</number>
-- <type>Equipment Lease</type>
-- <version type="integer">1</version>
-- <start-date type="dateTime">2021-12-20T00:00:00+05:30</start-date>
-- <end-date type="dateTime">2022-12-20T00:00:00+05:30</end-date>
-- <status>draft</status>
-- <minimum-value type="decimal">100.00</minimum-value>
-- <maximum-value type="decimal">2000.00</maximum-value>
-- <stop-spend-based-on-max-value>Yes</stop-spend-based-on-max-value>
-- <terms>Annual</terms>
-- <savings-pct>10</savings-pct>
-- <supplier-invoiceable type="boolean">true</supplier-invoiceable>
-- <is-default type="boolean">true</is-default>
-- <preferred nil="true"/>
-- <min-commit type="decimal">0.00</min-commit>
-- <max-commit type="decimal">0.00</max-commit>
-- <supplier-account/>
-- <use-order-windows type="boolean">false</use-order-windows>
-- <order-window-tz>Asia/Kolkata</order-window-tz>
-- <requisition-message/>
-- <po-message/>
-- <legal-agreement-url nil="true"/>
-- <current-approval nil="true"/>
-- <used-for-buying type="boolean">true</used-for-buying>
-- <strict-invoicing-rules type="boolean">false</strict-invoicing-rules>
-- <term-type nil="true"/>
-- <auto-extend-end-date-for-renewal type="boolean">false</auto-extend-end-date-for-renewal>
-- <terminated type="boolean">false</terminated>
-- <termination-notice nil="true"/>
-- <termination-notice-length-unit nil="true"/>
-- <termination-notice-length-value nil="true"/>
-- <consent nil="true"/>
-- <no-of-renewals nil="true"/>
-- <renewal-length-unit nil="true"/>
-- <renewal-length-value nil="true"/>
-- <length-of-notice-unit nil="true"/>
-- <length-of-notice-value nil="true"/>
-- <source-id nil="true"/>
-- <source-type nil="true"/>
-- <source nil="true"/>
-- <amended-contract-type nil="true"/>
-- <quote-response-id nil="true"/>
-- <description/>
-- <execution-date nil="true"/>
-- <supplier>
-- <number>123456</number>
-- </supplier>
-- <currency>
-- <code>USD</code>
-- </currency>
-- <content-groups type="array">
-- <content-group>
-- <name>Everyone</name>
-- </content-group>
-- </content-groups>
-- <reason-insight-events type="array"/>
-- <schedule>
-- <day0>anytime</day0>
-- <day1>anytime</day1>
-- <day2>anytime</day2>
-- <day3>anytime</day3>
-- <day4>anytime</day4>
-- <day5>anytime</day5>
-- <day6>anytime</day6>
-- </schedule>
-- <contract-terms type="array"/>
-- <submitter>
-- <login>coupasam</login>
-- </submitter>
-- <tags type="array"/>
-- <taggings type="array"/>
-- <contract-owner>
-- <login>coupasam</login>
-- </contract-owner>
-- </contract>
--
DECLARE @xml int
-- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT
EXEC sp_OASetProperty @xml, 'Tag', 'contract'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'name', 'Test API Contract 159753'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'number', 159753
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'type', 'Equipment Lease'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'version', 1, 'type', 'integer'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'version', 1
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'start-date', 1, 'type', 'dateTime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'start-date', '2021-12-20T00:00:00+05:30'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'end-date', 1, 'type', 'dateTime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'end-date', '2022-12-20T00:00:00+05:30'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'status', 'draft'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'minimum-value', 1, 'type', 'decimal'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'minimum-value', '100.00'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'maximum-value', 1, 'type', 'decimal'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'maximum-value', '2000.00'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'stop-spend-based-on-max-value', 'Yes'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'terms', 'Annual'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'savings-pct', 10
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'supplier-invoiceable', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'supplier-invoiceable', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'is-default', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'is-default', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'preferred', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'min-commit', 1, 'type', 'decimal'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'min-commit', '0.00'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'max-commit', 1, 'type', 'decimal'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'max-commit', '0.00'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'supplier-account', ''
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'use-order-windows', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'use-order-windows', 'false'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'order-window-tz', 'Asia/Kolkata'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-message', ''
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'po-message', ''
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'legal-agreement-url', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'current-approval', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'used-for-buying', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'used-for-buying', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'strict-invoicing-rules', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'strict-invoicing-rules', 'false'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'term-type', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'auto-extend-end-date-for-renewal', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'auto-extend-end-date-for-renewal', 'false'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'terminated', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'terminated', 'false'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'termination-notice', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'termination-notice-length-unit', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'termination-notice-length-value', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'consent', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'no-of-renewals', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'renewal-length-unit', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'renewal-length-value', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'length-of-notice-unit', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'length-of-notice-value', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'source-id', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'source-type', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'source', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'amended-contract-type', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'quote-response-id', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'description', ''
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'execution-date', 1, 'nil', 'true'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'supplier|number', 123456
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'currency|code', 'USD'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'content-groups', 1, 'type', 'array'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'content-groups|content-group|name', 'Everyone'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'reason-insight-events', 1, 'type', 'array'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'schedule|day0', 'anytime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'schedule|day1', 'anytime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'schedule|day2', 'anytime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'schedule|day3', 'anytime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'schedule|day4', 'anytime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'schedule|day5', 'anytime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'schedule|day6', 'anytime'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'contract-terms', 1, 'type', 'array'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'submitter|login', 'coupasam'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'tags', 1, 'type', 'array'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'taggings', 1, 'type', 'array'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'contract-owner|login', 'coupasam'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
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 @xml, 'GetXmlSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', 'https://domain.com/contracts/', @sbRequestBody, 'utf-8', 'application/xml', 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 @xml
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 @xml
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '<?xml version="1.0" encoding="UTF-8"?>
<contract>
<name>Test API Contract 159753</name>
<number>159753</number>
<type>Equipment Lease</type>
<version type="integer">1</version>
<start-date type="dateTime">2021-12-20T00:00:00+05:30</start-date>
<end-date type="dateTime">2022-12-20T00:00:00+05:30</end-date>
<status>draft</status>
<minimum-value type="decimal">100.00</minimum-value>
<maximum-value type="decimal">2000.00</maximum-value>
<stop-spend-based-on-max-value>Yes</stop-spend-based-on-max-value>
<terms>Annual</terms>
<savings-pct>10</savings-pct>
<supplier-invoiceable type="boolean">true</supplier-invoiceable>
<is-default type="boolean">true</is-default>
<preferred nil="true"/>
<min-commit type="decimal">0.00</min-commit>
<max-commit type="decimal">0.00</max-commit>
<supplier-account></supplier-account>
<use-order-windows type="boolean">false</use-order-windows>
<order-window-tz>Asia/Kolkata</order-window-tz>
<requisition-message></requisition-message>
<po-message></po-message>
<legal-agreement-url nil="true"/>
<current-approval nil="true"/>
<used-for-buying type="boolean">true</used-for-buying>
<strict-invoicing-rules type="boolean">false</strict-invoicing-rules>
<term-type nil="true"/>
<auto-extend-end-date-for-renewal type="boolean">false</auto-extend-end-date-for-renewal>
<terminated type="boolean">false</terminated>
<termination-notice nil="true"/>
<termination-notice-length-unit nil="true"/>
<termination-notice-length-value nil="true"/>
<consent nil="true"/>
<no-of-renewals nil="true"/>
<renewal-length-unit nil="true"/>
<renewal-length-value nil="true"/>
<length-of-notice-unit nil="true"/>
<length-of-notice-value nil="true"/>
<source-id nil="true"/>
<source-type nil="true"/>
<source nil="true"/>
<amended-contract-type nil="true"/>
<quote-response-id nil="true"/>
<description></description>
<execution-date nil="true"/>
<supplier>
<number>123456</number>
</supplier>
<currency>
<code>USD</code>
</currency>
<content-groups type="array">
<content-group>
<name>Everyone</name>
</content-group>
</content-groups>
<reason-insight-events type="array"/>
<schedule>
<day0>anytime</day0>
<day1>anytime</day1>
<day2>anytime</day2>
<day3>anytime</day3>
<day4>anytime</day4>
<day5>anytime</day5>
<day6>anytime</day6>
</schedule>
<contract-terms type="array"/>
<submitter>
<login>coupasam</login>
</submitter>
<tags type="array"/>
<taggings type="array"/>
<contract-owner>
<login>coupasam</login>
</contract-owner>
</contract>'
https://domain.com/contracts/
Postman Collection Item JSON
{
"name": "Create a Contract",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<contract>\n <name>Test API Contract 159753</name>\n <number>159753</number>\n <type>Equipment Lease</type>\n <version type=\"integer\">1</version>\n <start-date type=\"dateTime\">2021-12-20T00:00:00+05:30</start-date>\n <end-date type=\"dateTime\">2022-12-20T00:00:00+05:30</end-date>\n <status>draft</status>\n <minimum-value type=\"decimal\">100.00</minimum-value>\n <maximum-value type=\"decimal\">2000.00</maximum-value>\n <stop-spend-based-on-max-value>Yes</stop-spend-based-on-max-value>\n <terms>Annual</terms>\n <savings-pct>10</savings-pct>\n <supplier-invoiceable type=\"boolean\">true</supplier-invoiceable>\n <is-default type=\"boolean\">true</is-default>\n <preferred nil=\"true\"/>\n <min-commit type=\"decimal\">0.00</min-commit>\n <max-commit type=\"decimal\">0.00</max-commit>\n <supplier-account></supplier-account>\n <use-order-windows type=\"boolean\">false</use-order-windows>\n <order-window-tz>Asia/Kolkata</order-window-tz>\n <requisition-message></requisition-message>\n <po-message></po-message>\n <legal-agreement-url nil=\"true\"/>\n <current-approval nil=\"true\"/>\n <used-for-buying type=\"boolean\">true</used-for-buying>\n <strict-invoicing-rules type=\"boolean\">false</strict-invoicing-rules>\n <term-type nil=\"true\"/>\n <auto-extend-end-date-for-renewal type=\"boolean\">false</auto-extend-end-date-for-renewal>\n <terminated type=\"boolean\">false</terminated>\n <termination-notice nil=\"true\"/>\n <termination-notice-length-unit nil=\"true\"/>\n <termination-notice-length-value nil=\"true\"/>\n <consent nil=\"true\"/>\n <no-of-renewals nil=\"true\"/>\n <renewal-length-unit nil=\"true\"/>\n <renewal-length-value nil=\"true\"/>\n <length-of-notice-unit nil=\"true\"/>\n <length-of-notice-value nil=\"true\"/>\n <source-id nil=\"true\"/>\n <source-type nil=\"true\"/>\n <source nil=\"true\"/>\n <amended-contract-type nil=\"true\"/>\n <quote-response-id nil=\"true\"/>\n <description></description>\n <execution-date nil=\"true\"/>\n <supplier>\n <number>123456</number>\n </supplier>\n <currency>\n <code>USD</code>\n </currency>\n <content-groups type=\"array\">\n <content-group>\n <name>Everyone</name>\n </content-group>\n </content-groups>\n <reason-insight-events type=\"array\"/>\n <schedule>\n <day0>anytime</day0>\n <day1>anytime</day1>\n <day2>anytime</day2>\n <day3>anytime</day3>\n <day4>anytime</day4>\n <day5>anytime</day5>\n <day6>anytime</day6>\n </schedule>\n <contract-terms type=\"array\"/>\n <submitter>\n <login>coupasam</login>\n </submitter>\n <tags type=\"array\"/>\n <taggings type=\"array\"/>\n <contract-owner>\n <login>coupasam</login>\n </contract-owner>\n</contract>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/contracts/",
"host": [
"{{URL}}"
],
"path": [
"contracts",
""
]
}
},
"response": [
]
}