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"?>
// <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">5810</id>
// <description>Test</description>
// <line-num type="integer">1</line-num>
// <total type="decimal">20.00</total>
// <line-type>RequisitionAmountLine</line-type>
// <unit-price type="decimal">20.00</unit-price>
// <need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
// <account>
// <name>Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1</name>
// <code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>
// <active type="boolean">true</active>
// <segment-1>DUM_SEG_1_LV_1</segment-1>
// <segment-2>DUM_SEG_2_LV_1</segment-2>
// <account-type>
// <id type="integer">29</id>
// <created-at type="dateTime">2020-05-04T13:18:59-05:00</created-at>
// <updated-at type="dateTime">2020-05-04T13:18:59-05:00</updated-at>
// <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 = CkXmlW_Create();
CkXmlW_putTag(xml,L"requisition-header");
CkXmlW_UpdateChildContent(xml,L"justification",L"Test");
CkXmlW_UpdateChildContent(xml,L"ship-to-attention",L"Coupa Buyer");
CkXmlW_UpdateChildContent(xml,L"currency|code",L"USD");
CkXmlW_UpdateChildContent(xml,L"requested-by|login",L"CoupaSam");
CkXmlW_UpdateChildContent(xml,L"requested-by|email",L"CoupaSam@coupa.com");
CkXmlW_UpdateChildContent(xml,L"ship-to-address|location-code",L"DUMMYST");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines",TRUE,L"type",L"array");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|id",TRUE,L"type",L"integer");
CkXmlW_UpdateChildContentInt(xml,L"requisition-lines|requisition-line|id",5810);
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|description",L"Test");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|line-num",TRUE,L"type",L"integer");
CkXmlW_UpdateChildContentInt(xml,L"requisition-lines|requisition-line|line-num",1);
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|total",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|total",L"20.00");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|line-type",L"RequisitionAmountLine");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|unit-price",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|unit-price",L"20.00");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|need-by-date",TRUE,L"type",L"dateTime");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|need-by-date",L"2020-05-15T00:00:00-05:00");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|name",L"Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|code",L"DUM_SEG_1_LV_1-DUM_SEG_2_LV_1");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|account|active",TRUE,L"type",L"boolean");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|active",L"true");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|segment-1",L"DUM_SEG_1_LV_1");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|segment-2",L"DUM_SEG_2_LV_1");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|account|account-type|id",TRUE,L"type",L"integer");
CkXmlW_UpdateChildContentInt(xml,L"requisition-lines|requisition-line|account|account-type|id",29);
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|account|account-type|created-at",TRUE,L"type",L"dateTime");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|account-type|created-at",L"2020-05-04T13:18:59-05:00");
CkXmlW_UpdateAttrAt(xml,L"requisition-lines|requisition-line|account|account-type|updated-at",TRUE,L"type",L"dateTime");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|account-type|updated-at",L"2020-05-04T13:18:59-05:00");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|account-type|name",L"Dummy Chart of Accounts");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|account|account-type|currency|code",L"USD");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|currency|code",L"USD");
CkXmlW_UpdateChildContent(xml,L"requisition-lines|requisition-line|supplier|name",L"CoupaTester");
CkXmlW_UpdateChildContentInt(xml,L"requisition-lines|requisition-line|supplier|number",123456);
// 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"PUT",L"https://domain.com/requisitions/:id/update_and_submit_for_approval?fields=[\"id\"]",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 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">5810</id>
<description>Test</description>
<line-num type="integer">1</line-num>
<total type="decimal">20.00</total>
<line-type>RequisitionAmountLine</line-type>
<unit-price type="decimal">20.00</unit-price>
<need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
<account>
<name>Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1</name>
<code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>
<active type="boolean">true</active>
<segment-1>DUM_SEG_1_LV_1</segment-1>
<segment-2>DUM_SEG_2_LV_1</segment-2>
<account-type>
<id type="integer">29</id>
<created-at type="dateTime">2020-05-04T13:18:59-05:00</created-at>
<updated-at type="dateTime">2020-05-04T13:18:59-05:00</updated-at>
<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/:id/update_and_submit_for_approval?fields=["id"]
Postman Collection Item JSON
{
"name": "Update a Requisition in Draft Status and Submit for Approval",
"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\">5810</id>\n <description>Test</description>\n <line-num type=\"integer\">1</line-num>\n <total type=\"decimal\">20.00</total>\n <line-type>RequisitionAmountLine</line-type>\n <unit-price type=\"decimal\">20.00</unit-price>\n <need-by-date type=\"dateTime\">2020-05-15T00:00:00-05:00</need-by-date>\n <account>\n <name>Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1</name>\n <code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>\n <active type=\"boolean\">true</active>\n <segment-1>DUM_SEG_1_LV_1</segment-1>\n <segment-2>DUM_SEG_2_LV_1</segment-2>\n <account-type>\n <id type=\"integer\">29</id>\n <created-at type=\"dateTime\">2020-05-04T13:18:59-05:00</created-at>\n <updated-at type=\"dateTime\">2020-05-04T13:18:59-05:00</updated-at>\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/:id/update_and_submit_for_approval?fields=[\"id\"]",
"host": [
"{{URL}}"
],
"path": [
"requisitions",
":id",
"update_and_submit_for_approval"
],
"query": [
{
"key": "fields",
"value": "[\"id\"]"
}
],
"variable": [
{
"key": "id",
"value": "4012",
"description": "Coupa Internal Requisition Id"
}
]
}
},
"response": [
]
}