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"?>
-- <requisition-header>
-- <justification>Test</justification>
-- <ship-to-attention>Coupa Buyer</ship-to-attention>
-- <currency>
-- <code>USD</code>
-- </currency>
-- <requested-by>
-- <login>CoupaSam</login>
-- <email>CoupaSam@coupa.com</email>
-- </requested-by>
-- <ship-to-address>
-- <location-code>DUMMYST</location-code>
-- </ship-to-address>
-- <requisition-lines type="array">
-- <requisition-line>
-- <id type="integer">5809</id>
-- <description>Test</description>
-- <line-num type="integer">1</line-num>
-- <total type="decimal">12.00</total>
-- <line-type>RequisitionAmountLine</line-type>
-- <unit-price type="decimal">12.00</unit-price>
-- <need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
-- <account>
-- <code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>
-- <active type="boolean">true</active>
-- <segment-1>DUM2_SEG_1_LV_1</segment-1>
-- <segment-2>DUM2_SEG_2_LV_2</segment-2>
-- <account-type>
-- <name>Dummy 2 Chart of Accounts</name>
-- <currency>
-- <code>USD</code>
-- </currency>
-- </account-type>
-- </account>
-- <currency>
-- <code>USD</code>
-- </currency>
-- <supplier>
-- <name>CoupaTester</name>
-- <number>123456</number>
-- </supplier>
-- </requisition-line>
-- </requisition-lines>
-- </requisition-header>
--
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', 'requisition-header'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'justification', 'Test'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'ship-to-attention', 'Coupa Buyer'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'currency|code', 'USD'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requested-by|login', 'CoupaSam'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requested-by|email', 'CoupaSam@coupa.com'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'ship-to-address|location-code', 'DUMMYST'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'requisition-lines', 1, 'type', 'array'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'requisition-lines|requisition-line|id', 1, 'type', 'integer'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'requisition-lines|requisition-line|id', 5809
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|description', 'Test'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'requisition-lines|requisition-line|line-num', 1, 'type', 'integer'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'requisition-lines|requisition-line|line-num', 1
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'requisition-lines|requisition-line|total', 1, 'type', 'decimal'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|total', '12.00'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|line-type', 'RequisitionAmountLine'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'requisition-lines|requisition-line|unit-price', 1, 'type', 'decimal'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|unit-price', '12.00'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'requisition-lines|requisition-line|need-by-date', 1, 'type', 'dateTime'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|need-by-date', '2020-05-15T00:00:00-05:00'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|account|code', 'DUM_SEG_1_LV_1-DUM_SEG_2_LV_1'
EXEC sp_OAMethod @xml, 'UpdateAttrAt', @success OUT, 'requisition-lines|requisition-line|account|active', 1, 'type', 'boolean'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|account|active', 'true'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|account|segment-1', 'DUM2_SEG_1_LV_1'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|account|segment-2', 'DUM2_SEG_2_LV_2'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|account|account-type|name', 'Dummy 2 Chart of Accounts'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|account|account-type|currency|code', 'USD'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|currency|code', 'USD'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'requisition-lines|requisition-line|supplier|name', 'CoupaTester'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'requisition-lines|requisition-line|supplier|number', 123456
-- 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, 'PUT', 'https://domain.com/requisitions/:id?fields=["id"]', @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 PUT
-H "Authorization: Bearer <access_token>"
-d '<?xml version="1.0" encoding="UTF-8"?>
<requisition-header>
<justification>Test</justification>
<ship-to-attention>Coupa Buyer</ship-to-attention>
<currency>
<code>USD</code>
</currency>
<requested-by>
<login>CoupaSam</login>
<email>CoupaSam@coupa.com</email>
</requested-by>
<ship-to-address>
<location-code>DUMMYST</location-code>
</ship-to-address>
<requisition-lines type="array">
<requisition-line>
<id type="integer">5809</id>
<description>Test</description>
<line-num type="integer">1</line-num>
<total type="decimal">12.00</total>
<line-type>RequisitionAmountLine</line-type>
<unit-price type="decimal">12.00</unit-price>
<need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
<account>
<code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>
<active type="boolean">true</active>
<segment-1>DUM2_SEG_1_LV_1</segment-1>
<segment-2>DUM2_SEG_2_LV_2</segment-2>
<account-type>
<name>Dummy 2 Chart of Accounts</name>
<currency>
<code>USD</code>
</currency>
</account-type>
</account>
<currency>
<code>USD</code>
</currency>
<supplier>
<name>CoupaTester</name>
<number>123456</number>
</supplier>
</requisition-line>
</requisition-lines>
</requisition-header>'
https://domain.com/requisitions/:id?fields=["id"]
Postman Collection Item JSON
{
"name": "Update a Requisition in Draft Status",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<requisition-header>\n <justification>Test</justification>\n <ship-to-attention>Coupa Buyer</ship-to-attention>\n <currency>\n <code>USD</code>\n </currency>\n <requested-by>\n <login>CoupaSam</login>\n <email>CoupaSam@coupa.com</email>\n </requested-by>\n <ship-to-address>\n <location-code>DUMMYST</location-code>\n </ship-to-address>\n <requisition-lines type=\"array\">\n <requisition-line>\n \t<id type=\"integer\">5809</id>\n <description>Test</description>\n <line-num type=\"integer\">1</line-num>\n <total type=\"decimal\">12.00</total>\n <line-type>RequisitionAmountLine</line-type>\n <unit-price type=\"decimal\">12.00</unit-price>\n <need-by-date type=\"dateTime\">2020-05-15T00:00:00-05:00</need-by-date>\n <account>\n <code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>\n <active type=\"boolean\">true</active>\n <segment-1>DUM2_SEG_1_LV_1</segment-1>\n <segment-2>DUM2_SEG_2_LV_2</segment-2>\n <account-type>\n <name>Dummy 2 Chart of Accounts</name>\n <currency>\n <code>USD</code>\n </currency>\n </account-type>\n </account>\n <currency>\n <code>USD</code>\n </currency>\n <supplier>\n <name>CoupaTester</name>\n <number>123456</number>\n </supplier>\n </requisition-line>\n </requisition-lines>\n</requisition-header>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/requisitions/:id?fields=[\"id\"]",
"host": [
"{{URL}}"
],
"path": [
"requisitions",
":id"
],
"query": [
{
"key": "fields",
"value": "[\"id\"]"
}
],
"variable": [
{
"key": "id",
"value": "3462",
"description": "Coupa Internal Requisition Id"
}
]
}
},
"response": [
]
}