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-term>
// <name>API Contract Term 1</name>
// <contract-term-type>PriceRangeContractTerm</contract-term-type>
// <use-pct-discounts type="boolean">true</use-pct-discounts>
// <tier-1-upper-bound type="decimal">15.0</tier-1-upper-bound>
// <tier-1-disc-pct type="decimal">6.0</tier-1-disc-pct>
// <tier-2-disc-pct type="decimal">7.0</tier-2-disc-pct>
// </contract-term>
//
xml = CkXml_Create();
CkXml_putTag(xml,"contract-term");
CkXml_UpdateChildContent(xml,"name","API Contract Term 1");
CkXml_UpdateChildContent(xml,"contract-term-type","PriceRangeContractTerm");
CkXml_UpdateAttrAt(xml,"use-pct-discounts",TRUE,"type","boolean");
CkXml_UpdateChildContent(xml,"use-pct-discounts","true");
CkXml_UpdateAttrAt(xml,"tier-1-upper-bound",TRUE,"type","decimal");
CkXml_UpdateChildContent(xml,"tier-1-upper-bound","15.0");
CkXml_UpdateAttrAt(xml,"tier-1-disc-pct",TRUE,"type","decimal");
CkXml_UpdateChildContent(xml,"tier-1-disc-pct","6.0");
CkXml_UpdateAttrAt(xml,"tier-2-disc-pct",TRUE,"type","decimal");
CkXml_UpdateChildContent(xml,"tier-2-disc-pct","7.0");
// 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/:id/contract_terms",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-term>
<name>API Contract Term 1</name>
<contract-term-type>PriceRangeContractTerm</contract-term-type>
<use-pct-discounts type="boolean">true</use-pct-discounts>
<tier-1-upper-bound type="decimal">15.0</tier-1-upper-bound>
<tier-1-disc-pct type="decimal">6.0</tier-1-disc-pct>
<tier-2-disc-pct type="decimal">7.0</tier-2-disc-pct>
</contract-term>'
https://domain.com/contracts/:id/contract_terms
Postman Collection Item JSON
{
"name": "Add contract term",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<contract-term>\n <name>API Contract Term 1</name>\n <contract-term-type>PriceRangeContractTerm</contract-term-type>\n <use-pct-discounts type=\"boolean\">true</use-pct-discounts>\n <tier-1-upper-bound type=\"decimal\">15.0</tier-1-upper-bound>\n <tier-1-disc-pct type=\"decimal\">6.0</tier-1-disc-pct>\n <tier-2-disc-pct type=\"decimal\">7.0</tier-2-disc-pct>\n</contract-term>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/contracts/:id/contract_terms",
"host": [
"{{URL}}"
],
"path": [
"contracts",
":id",
"contract_terms"
],
"variable": [
{
"key": "id",
"value": "377",
"type": "string"
}
]
}
},
"response": [
]
}