Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkXmlW xml;
HCkStringBuilderW sbRequestBody;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// 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>
//
xml = CkXmlW_Create();
CkXmlW_putTag(xml,L"contract");
CkXmlW_UpdateChildContent(xml,L"name",L"Test API Contract 159753");
CkXmlW_UpdateChildContentInt(xml,L"number",159753);
CkXmlW_UpdateChildContent(xml,L"type",L"Equipment Lease");
CkXmlW_UpdateAttrAt(xml,L"version",TRUE,L"type",L"integer");
CkXmlW_UpdateChildContentInt(xml,L"version",1);
CkXmlW_UpdateAttrAt(xml,L"start-date",TRUE,L"type",L"dateTime");
CkXmlW_UpdateChildContent(xml,L"start-date",L"2021-12-20T00:00:00+05:30");
CkXmlW_UpdateAttrAt(xml,L"end-date",TRUE,L"type",L"dateTime");
CkXmlW_UpdateChildContent(xml,L"end-date",L"2022-12-20T00:00:00+05:30");
CkXmlW_UpdateChildContent(xml,L"status",L"draft");
CkXmlW_UpdateAttrAt(xml,L"minimum-value",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"minimum-value",L"100.00");
CkXmlW_UpdateAttrAt(xml,L"maximum-value",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"maximum-value",L"2000.00");
CkXmlW_UpdateChildContent(xml,L"stop-spend-based-on-max-value",L"Yes");
CkXmlW_UpdateChildContent(xml,L"terms",L"Annual");
CkXmlW_UpdateChildContentInt(xml,L"savings-pct",10);
CkXmlW_UpdateAttrAt(xml,L"supplier-invoiceable",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"supplier-invoiceable",L"true");
CkXmlW_UpdateAttrAt(xml,L"is-default",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"is-default",L"true");
CkXmlW_UpdateAttrAt(xml,L"preferred",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"min-commit",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"min-commit",L"0.00");
CkXmlW_UpdateAttrAt(xml,L"max-commit",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"max-commit",L"0.00");
CkXmlW_UpdateChildContent(xml,L"supplier-account",L"");
CkXmlW_UpdateAttrAt(xml,L"use-order-windows",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"use-order-windows",L"false");
CkXmlW_UpdateChildContent(xml,L"order-window-tz",L"Asia/Kolkata");
CkXmlW_UpdateChildContent(xml,L"requisition-message",L"");
CkXmlW_UpdateChildContent(xml,L"po-message",L"");
CkXmlW_UpdateAttrAt(xml,L"legal-agreement-url",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"current-approval",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"used-for-buying",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"used-for-buying",L"true");
CkXmlW_UpdateAttrAt(xml,L"strict-invoicing-rules",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"strict-invoicing-rules",L"false");
CkXmlW_UpdateAttrAt(xml,L"term-type",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"auto-extend-end-date-for-renewal",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"auto-extend-end-date-for-renewal",L"false");
CkXmlW_UpdateAttrAt(xml,L"terminated",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"terminated",L"false");
CkXmlW_UpdateAttrAt(xml,L"termination-notice",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"termination-notice-length-unit",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"termination-notice-length-value",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"consent",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"no-of-renewals",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"renewal-length-unit",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"renewal-length-value",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"length-of-notice-unit",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"length-of-notice-value",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"source-id",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"source-type",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"source",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"amended-contract-type",TRUE,L"nil",L"true");
CkXmlW_UpdateAttrAt(xml,L"quote-response-id",TRUE,L"nil",L"true");
CkXmlW_UpdateChildContent(xml,L"description",L"");
CkXmlW_UpdateAttrAt(xml,L"execution-date",TRUE,L"nil",L"true");
CkXmlW_UpdateChildContentInt(xml,L"supplier|number",123456);
CkXmlW_UpdateChildContent(xml,L"currency|code",L"USD");
CkXmlW_UpdateAttrAt(xml,L"content-groups",TRUE,L"type",L"array");
CkXmlW_UpdateChildContent(xml,L"content-groups|content-group|name",L"Everyone");
CkXmlW_UpdateAttrAt(xml,L"reason-insight-events",TRUE,L"type",L"array");
CkXmlW_UpdateChildContent(xml,L"schedule|day0",L"anytime");
CkXmlW_UpdateChildContent(xml,L"schedule|day1",L"anytime");
CkXmlW_UpdateChildContent(xml,L"schedule|day2",L"anytime");
CkXmlW_UpdateChildContent(xml,L"schedule|day3",L"anytime");
CkXmlW_UpdateChildContent(xml,L"schedule|day4",L"anytime");
CkXmlW_UpdateChildContent(xml,L"schedule|day5",L"anytime");
CkXmlW_UpdateChildContent(xml,L"schedule|day6",L"anytime");
CkXmlW_UpdateAttrAt(xml,L"contract-terms",TRUE,L"type",L"array");
CkXmlW_UpdateChildContent(xml,L"submitter|login",L"coupasam");
CkXmlW_UpdateAttrAt(xml,L"tags",TRUE,L"type",L"array");
CkXmlW_UpdateAttrAt(xml,L"taggings",TRUE,L"type",L"array");
CkXmlW_UpdateChildContent(xml,L"contract-owner|login",L"coupasam");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
sbRequestBody = CkStringBuilderW_Create();
CkXmlW_GetXmlSb(xml,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"POST",L"https://domain.com/contracts/",sbRequestBody,L"utf-8",L"application/xml",FALSE,FALSE);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkStringBuilderW_Dispose(sbRequestBody);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkStringBuilderW_Dispose(sbRequestBody);
}
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": [
]
}