Chilkat Online Tools

C / Coupa Postman Collection - OAuth - Master / Create a Contract

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkXml.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkXml xml;
    HCkStringBuilder sbRequestBody;
    HCkHttpResponse resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttp_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 = CkXml_Create();
    CkXml_putTag(xml,"contract");
    CkXml_UpdateChildContent(xml,"name","Test API Contract 159753");
    CkXml_UpdateChildContentInt(xml,"number",159753);
    CkXml_UpdateChildContent(xml,"type","Equipment Lease");
    CkXml_UpdateAttrAt(xml,"version",TRUE,"type","integer");
    CkXml_UpdateChildContentInt(xml,"version",1);
    CkXml_UpdateAttrAt(xml,"start-date",TRUE,"type","dateTime");
    CkXml_UpdateChildContent(xml,"start-date","2021-12-20T00:00:00+05:30");
    CkXml_UpdateAttrAt(xml,"end-date",TRUE,"type","dateTime");
    CkXml_UpdateChildContent(xml,"end-date","2022-12-20T00:00:00+05:30");
    CkXml_UpdateChildContent(xml,"status","draft");
    CkXml_UpdateAttrAt(xml,"minimum-value",TRUE,"type","decimal");
    CkXml_UpdateChildContent(xml,"minimum-value","100.00");
    CkXml_UpdateAttrAt(xml,"maximum-value",TRUE,"type","decimal");
    CkXml_UpdateChildContent(xml,"maximum-value","2000.00");
    CkXml_UpdateChildContent(xml,"stop-spend-based-on-max-value","Yes");
    CkXml_UpdateChildContent(xml,"terms","Annual");
    CkXml_UpdateChildContentInt(xml,"savings-pct",10);
    CkXml_UpdateAttrAt(xml,"supplier-invoiceable",TRUE,"type","boolean");
    CkXml_UpdateChildContent(xml,"supplier-invoiceable","true");
    CkXml_UpdateAttrAt(xml,"is-default",TRUE,"type","boolean");
    CkXml_UpdateChildContent(xml,"is-default","true");
    CkXml_UpdateAttrAt(xml,"preferred",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"min-commit",TRUE,"type","decimal");
    CkXml_UpdateChildContent(xml,"min-commit","0.00");
    CkXml_UpdateAttrAt(xml,"max-commit",TRUE,"type","decimal");
    CkXml_UpdateChildContent(xml,"max-commit","0.00");
    CkXml_UpdateChildContent(xml,"supplier-account","");
    CkXml_UpdateAttrAt(xml,"use-order-windows",TRUE,"type","boolean");
    CkXml_UpdateChildContent(xml,"use-order-windows","false");
    CkXml_UpdateChildContent(xml,"order-window-tz","Asia/Kolkata");
    CkXml_UpdateChildContent(xml,"requisition-message","");
    CkXml_UpdateChildContent(xml,"po-message","");
    CkXml_UpdateAttrAt(xml,"legal-agreement-url",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"current-approval",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"used-for-buying",TRUE,"type","boolean");
    CkXml_UpdateChildContent(xml,"used-for-buying","true");
    CkXml_UpdateAttrAt(xml,"strict-invoicing-rules",TRUE,"type","boolean");
    CkXml_UpdateChildContent(xml,"strict-invoicing-rules","false");
    CkXml_UpdateAttrAt(xml,"term-type",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"auto-extend-end-date-for-renewal",TRUE,"type","boolean");
    CkXml_UpdateChildContent(xml,"auto-extend-end-date-for-renewal","false");
    CkXml_UpdateAttrAt(xml,"terminated",TRUE,"type","boolean");
    CkXml_UpdateChildContent(xml,"terminated","false");
    CkXml_UpdateAttrAt(xml,"termination-notice",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"termination-notice-length-unit",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"termination-notice-length-value",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"consent",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"no-of-renewals",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"renewal-length-unit",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"renewal-length-value",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"length-of-notice-unit",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"length-of-notice-value",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"source-id",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"source-type",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"source",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"amended-contract-type",TRUE,"nil","true");
    CkXml_UpdateAttrAt(xml,"quote-response-id",TRUE,"nil","true");
    CkXml_UpdateChildContent(xml,"description","");
    CkXml_UpdateAttrAt(xml,"execution-date",TRUE,"nil","true");
    CkXml_UpdateChildContentInt(xml,"supplier|number",123456);
    CkXml_UpdateChildContent(xml,"currency|code","USD");
    CkXml_UpdateAttrAt(xml,"content-groups",TRUE,"type","array");
    CkXml_UpdateChildContent(xml,"content-groups|content-group|name","Everyone");
    CkXml_UpdateAttrAt(xml,"reason-insight-events",TRUE,"type","array");
    CkXml_UpdateChildContent(xml,"schedule|day0","anytime");
    CkXml_UpdateChildContent(xml,"schedule|day1","anytime");
    CkXml_UpdateChildContent(xml,"schedule|day2","anytime");
    CkXml_UpdateChildContent(xml,"schedule|day3","anytime");
    CkXml_UpdateChildContent(xml,"schedule|day4","anytime");
    CkXml_UpdateChildContent(xml,"schedule|day5","anytime");
    CkXml_UpdateChildContent(xml,"schedule|day6","anytime");
    CkXml_UpdateAttrAt(xml,"contract-terms",TRUE,"type","array");
    CkXml_UpdateChildContent(xml,"submitter|login","coupasam");
    CkXml_UpdateAttrAt(xml,"tags",TRUE,"type","array");
    CkXml_UpdateAttrAt(xml,"taggings",TRUE,"type","array");
    CkXml_UpdateChildContent(xml,"contract-owner|login","coupasam");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttp_putAuthToken(http,"<access_token>");

    sbRequestBody = CkStringBuilder_Create();
    CkXml_GetXmlSb(xml,sbRequestBody);

    resp = CkHttp_PTextSb(http,"POST","https://domain.com/contracts/",sbRequestBody,"utf-8","application/xml",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkXml_Dispose(xml);
        CkStringBuilder_Dispose(sbRequestBody);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkXml_Dispose(xml);
    CkStringBuilder_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": [
  ]
}