Back to Collection Items
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
boolean success;
// 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>
//
CkXml xml = new CkXml();
xml.put_Tag("contract");
xml.UpdateChildContent("name","Test API Contract 159753");
xml.UpdateChildContentInt("number",159753);
xml.UpdateChildContent("type","Equipment Lease");
xml.UpdateAttrAt("version",true,"type","integer");
xml.UpdateChildContentInt("version",1);
xml.UpdateAttrAt("start-date",true,"type","dateTime");
xml.UpdateChildContent("start-date","2021-12-20T00:00:00+05:30");
xml.UpdateAttrAt("end-date",true,"type","dateTime");
xml.UpdateChildContent("end-date","2022-12-20T00:00:00+05:30");
xml.UpdateChildContent("status","draft");
xml.UpdateAttrAt("minimum-value",true,"type","decimal");
xml.UpdateChildContent("minimum-value","100.00");
xml.UpdateAttrAt("maximum-value",true,"type","decimal");
xml.UpdateChildContent("maximum-value","2000.00");
xml.UpdateChildContent("stop-spend-based-on-max-value","Yes");
xml.UpdateChildContent("terms","Annual");
xml.UpdateChildContentInt("savings-pct",10);
xml.UpdateAttrAt("supplier-invoiceable",true,"type","boolean");
xml.UpdateChildContent("supplier-invoiceable","true");
xml.UpdateAttrAt("is-default",true,"type","boolean");
xml.UpdateChildContent("is-default","true");
xml.UpdateAttrAt("preferred",true,"nil","true");
xml.UpdateAttrAt("min-commit",true,"type","decimal");
xml.UpdateChildContent("min-commit","0.00");
xml.UpdateAttrAt("max-commit",true,"type","decimal");
xml.UpdateChildContent("max-commit","0.00");
xml.UpdateChildContent("supplier-account","");
xml.UpdateAttrAt("use-order-windows",true,"type","boolean");
xml.UpdateChildContent("use-order-windows","false");
xml.UpdateChildContent("order-window-tz","Asia/Kolkata");
xml.UpdateChildContent("requisition-message","");
xml.UpdateChildContent("po-message","");
xml.UpdateAttrAt("legal-agreement-url",true,"nil","true");
xml.UpdateAttrAt("current-approval",true,"nil","true");
xml.UpdateAttrAt("used-for-buying",true,"type","boolean");
xml.UpdateChildContent("used-for-buying","true");
xml.UpdateAttrAt("strict-invoicing-rules",true,"type","boolean");
xml.UpdateChildContent("strict-invoicing-rules","false");
xml.UpdateAttrAt("term-type",true,"nil","true");
xml.UpdateAttrAt("auto-extend-end-date-for-renewal",true,"type","boolean");
xml.UpdateChildContent("auto-extend-end-date-for-renewal","false");
xml.UpdateAttrAt("terminated",true,"type","boolean");
xml.UpdateChildContent("terminated","false");
xml.UpdateAttrAt("termination-notice",true,"nil","true");
xml.UpdateAttrAt("termination-notice-length-unit",true,"nil","true");
xml.UpdateAttrAt("termination-notice-length-value",true,"nil","true");
xml.UpdateAttrAt("consent",true,"nil","true");
xml.UpdateAttrAt("no-of-renewals",true,"nil","true");
xml.UpdateAttrAt("renewal-length-unit",true,"nil","true");
xml.UpdateAttrAt("renewal-length-value",true,"nil","true");
xml.UpdateAttrAt("length-of-notice-unit",true,"nil","true");
xml.UpdateAttrAt("length-of-notice-value",true,"nil","true");
xml.UpdateAttrAt("source-id",true,"nil","true");
xml.UpdateAttrAt("source-type",true,"nil","true");
xml.UpdateAttrAt("source",true,"nil","true");
xml.UpdateAttrAt("amended-contract-type",true,"nil","true");
xml.UpdateAttrAt("quote-response-id",true,"nil","true");
xml.UpdateChildContent("description","");
xml.UpdateAttrAt("execution-date",true,"nil","true");
xml.UpdateChildContentInt("supplier|number",123456);
xml.UpdateChildContent("currency|code","USD");
xml.UpdateAttrAt("content-groups",true,"type","array");
xml.UpdateChildContent("content-groups|content-group|name","Everyone");
xml.UpdateAttrAt("reason-insight-events",true,"type","array");
xml.UpdateChildContent("schedule|day0","anytime");
xml.UpdateChildContent("schedule|day1","anytime");
xml.UpdateChildContent("schedule|day2","anytime");
xml.UpdateChildContent("schedule|day3","anytime");
xml.UpdateChildContent("schedule|day4","anytime");
xml.UpdateChildContent("schedule|day5","anytime");
xml.UpdateChildContent("schedule|day6","anytime");
xml.UpdateAttrAt("contract-terms",true,"type","array");
xml.UpdateChildContent("submitter|login","coupasam");
xml.UpdateAttrAt("tags",true,"type","array");
xml.UpdateAttrAt("taggings",true,"type","array");
xml.UpdateChildContent("contract-owner|login","coupasam");
// Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>");
CkStringBuilder sbRequestBody = new CkStringBuilder();
xml.GetXmlSb(sbRequestBody);
CkHttpResponse resp = http.PTextSb("POST","https://domain.com/contracts/",sbRequestBody,"utf-8","application/xml",false,false);
if (http.get_LastMethodSuccess() == false) {
Log.i(TAG, http.lastErrorText());
return;
}
Log.i(TAG, String.valueOf(resp.get_StatusCode()));
Log.i(TAG, resp.bodyStr());
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
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": [
]
}