Chilkat Online Tools

C / Coupa Postman Collection - OAuth - Master / Create a Requisition in Draft Status

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"?>
    // <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>
    //             <description>Test</description>
    //             <line-num type="integer">1</line-num>
    //             <total type="decimal">10.00</total>
    //             <line-type>RequisitionAmountLine</line-type>
    //             <unit-price type="decimal">10.00</unit-price>
    //             <need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
    //             <account>
    //                 <code>DUM_1_SEG_1_LV_1-DUM_1_SEG_2_LV_1</code>
    //                 <account-type>
    //                     <name>Dummy 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>
    // 

    xml = CkXml_Create();
    CkXml_putTag(xml,"requisition-header");
    CkXml_UpdateChildContent(xml,"justification","Test");
    CkXml_UpdateChildContent(xml,"ship-to-attention","Coupa Buyer");
    CkXml_UpdateChildContent(xml,"currency|code","USD");
    CkXml_UpdateChildContent(xml,"requested-by|login","CoupaSam");
    CkXml_UpdateChildContent(xml,"requested-by|email","CoupaSam@coupa.com");
    CkXml_UpdateChildContent(xml,"ship-to-address|location-code","DUMMYST");
    CkXml_UpdateAttrAt(xml,"requisition-lines",TRUE,"type","array");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|description","Test");
    CkXml_UpdateAttrAt(xml,"requisition-lines|requisition-line|line-num",TRUE,"type","integer");
    CkXml_UpdateChildContentInt(xml,"requisition-lines|requisition-line|line-num",1);
    CkXml_UpdateAttrAt(xml,"requisition-lines|requisition-line|total",TRUE,"type","decimal");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|total","10.00");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|line-type","RequisitionAmountLine");
    CkXml_UpdateAttrAt(xml,"requisition-lines|requisition-line|unit-price",TRUE,"type","decimal");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|unit-price","10.00");
    CkXml_UpdateAttrAt(xml,"requisition-lines|requisition-line|need-by-date",TRUE,"type","dateTime");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|need-by-date","2020-05-15T00:00:00-05:00");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|account|code","DUM_1_SEG_1_LV_1-DUM_1_SEG_2_LV_1");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|account|account-type|name","Dummy Chart of Accounts");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|account|account-type|currency|code","USD");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|currency|code","USD");
    CkXml_UpdateChildContent(xml,"requisition-lines|requisition-line|supplier|name","CoupaTester");
    CkXml_UpdateChildContentInt(xml,"requisition-lines|requisition-line|supplier|number",123456);

    // 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/requisitions/?fields=[\"id\"]",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"?>
<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>
            <description>Test</description>
            <line-num type="integer">1</line-num>
            <total type="decimal">10.00</total>
            <line-type>RequisitionAmountLine</line-type>
            <unit-price type="decimal">10.00</unit-price>
            <need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
            <account>
                <code>DUM_1_SEG_1_LV_1-DUM_1_SEG_2_LV_1</code>
                <account-type>
                    <name>Dummy 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/?fields=["id"]

Postman Collection Item JSON

{
  "name": "Create a Requisition in Draft Status",
  "request": {
    "method": "POST",
    "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            <description>Test</description>\n            <line-num type=\"integer\">1</line-num>\n            <total type=\"decimal\">10.00</total>\n            <line-type>RequisitionAmountLine</line-type>\n            <unit-price type=\"decimal\">10.00</unit-price>\n            <need-by-date type=\"dateTime\">2020-05-15T00:00:00-05:00</need-by-date>\n            <account>\n                <code>DUM_1_SEG_1_LV_1-DUM_1_SEG_2_LV_1</code>\n                <account-type>\n                    <name>Dummy 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/?fields=[\"id\"]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "requisitions",
        ""
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\"]"
        }
      ]
    }
  },
  "response": [
  ]
}