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"?>
// <order-header>
// <type>ExternalOrderHeader</type>
// <po-number>PO-957645-17</po-number>
// <version type="integer">1</version>
// <payment-method>invoice</payment-method>
// <ship-to-attention nil="true"/>
// <transmission-method-override>do_not_transmit</transmission-method-override>
// <ship-to-address>
// <location-code>DUMMYST</location-code>
// </ship-to-address>
// <ship-to-user>
// <login>CoupaRequester</login>
// </ship-to-user>
// <supplier>
// <name>CoupaSupplier</name>
// </supplier>
// <payment-term>
// <code>2/10 Net 30</code>
// </payment-term>
// <currency>
// <code>USD</code>
// </currency>
// <order-lines type="array">
// <order-line>
// <description>Supplies</description>
// <line-num>1</line-num>
// <price type="decimal">40.00</price>
// <quantity type="decimal">1.0</quantity>
// <type>OrderQuantityLine</type>
// <uom>
// <code>EA</code>
// </uom>
// <account>
// <code>SF-Marketing-Assets</code>
// <account-type>
// <name>Ace Corporate</name>
// </account-type>
// </account>
// <currency>
// <code>USD</code>
// </currency>
// </order-line>
// </order-lines>
// </order-header>
//
xml = CkXmlW_Create();
CkXmlW_putTag(xml,L"order-header");
CkXmlW_UpdateChildContent(xml,L"type",L"ExternalOrderHeader");
CkXmlW_UpdateChildContent(xml,L"po-number",L"PO-957645-17");
CkXmlW_UpdateAttrAt(xml,L"version",TRUE,L"type",L"integer");
CkXmlW_UpdateChildContentInt(xml,L"version",1);
CkXmlW_UpdateChildContent(xml,L"payment-method",L"invoice");
CkXmlW_UpdateAttrAt(xml,L"ship-to-attention",TRUE,L"nil",L"true");
CkXmlW_UpdateChildContent(xml,L"transmission-method-override",L"do_not_transmit");
CkXmlW_UpdateChildContent(xml,L"ship-to-address|location-code",L"DUMMYST");
CkXmlW_UpdateChildContent(xml,L"ship-to-user|login",L"CoupaRequester");
CkXmlW_UpdateChildContent(xml,L"supplier|name",L"CoupaSupplier");
CkXmlW_UpdateChildContent(xml,L"payment-term|code",L"2/10 Net 30");
CkXmlW_UpdateChildContent(xml,L"currency|code",L"USD");
CkXmlW_UpdateAttrAt(xml,L"order-lines",TRUE,L"type",L"array");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|description",L"Supplies");
CkXmlW_UpdateChildContentInt(xml,L"order-lines|order-line|line-num",1);
CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|price",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|price",L"40.00");
CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|quantity",TRUE,L"type",L"decimal");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|quantity",L"1.0");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|type",L"OrderQuantityLine");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|uom|code",L"EA");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account|code",L"SF-Marketing-Assets");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account|account-type|name",L"Ace Corporate");
CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|currency|code",L"USD");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
sbRequestBody = CkStringBuilderW_Create();
CkXmlW_GetXmlSb(xml,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"POST",L"https://domain.com/purchase_orders/?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 POST
-H "Authorization: Bearer <access_token>"
-H "Accept: application/json"
-d '<?xml version="1.0" encoding="UTF-8"?>
<order-header>
<type>ExternalOrderHeader</type>
<po-number>PO-957645-17</po-number>
<version type="integer">1</version>
<payment-method>invoice</payment-method>
<ship-to-attention nil="true"/>
<transmission-method-override>do_not_transmit</transmission-method-override>
<ship-to-address>
<location-code>DUMMYST</location-code>
</ship-to-address>
<ship-to-user>
<login>CoupaRequester</login>
</ship-to-user>
<supplier>
<name>CoupaSupplier</name>
</supplier>
<payment-term>
<code>2/10 Net 30</code>
</payment-term>
<currency>
<code>USD</code>
</currency>
<order-lines type="array">
<order-line>
<description>Supplies</description>
<line-num>1</line-num>
<price type="decimal">40.00</price>
<quantity type="decimal">1.0</quantity>
<type>OrderQuantityLine</type>
<uom>
<code>EA</code>
</uom>
<account>
<code>SF-Marketing-Assets</code>
<account-type>
<name>Ace Corporate</name>
</account-type>
</account>
<currency>
<code>USD</code>
</currency>
</order-line>
</order-lines>
</order-header>'
https://domain.com/purchase_orders/?fields=["id"]
Postman Collection Item JSON
{
"name": "Create External PO",
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<order-header>\n <type>ExternalOrderHeader</type>\n <po-number>PO-957645-17</po-number>\n <version type=\"integer\">1</version>\n <payment-method>invoice</payment-method>\n <ship-to-attention nil=\"true\"/>\n <transmission-method-override>do_not_transmit</transmission-method-override>\n <ship-to-address>\n <location-code>DUMMYST</location-code>\n </ship-to-address>\n <ship-to-user>\n <login>CoupaRequester</login>\n </ship-to-user>\n <supplier>\n <name>CoupaSupplier</name>\n </supplier>\n <payment-term>\n <code>2/10 Net 30</code>\n </payment-term>\n <currency>\n <code>USD</code>\n </currency>\n <order-lines type=\"array\">\n <order-line>\n <description>Supplies</description>\n <line-num>1</line-num>\n <price type=\"decimal\">40.00</price>\n <quantity type=\"decimal\">1.0</quantity>\n <type>OrderQuantityLine</type>\n <uom>\n <code>EA</code>\n </uom>\n <account>\n <code>SF-Marketing-Assets</code>\n <account-type>\n <name>Ace Corporate</name>\n </account-type>\n </account>\n <currency>\n <code>USD</code>\n </currency>\n </order-line>\n </order-lines>\n</order-header>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/purchase_orders/?fields=[\"id\"]",
"host": [
"{{URL}}"
],
"path": [
"purchase_orders",
""
],
"query": [
{
"key": "fields",
"value": "[\"id\"]"
}
]
}
},
"response": [
]
}