Back to Collection Items
        IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkXml.pb"
Procedure ChilkatExample()
    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.
    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf
    success.i
    ; 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"?>
    ; <department>
    ;     <name>Coupa Development</name>
    ;     <active>true</active>
    ;     <custom-fields>
    ;         <test1>TestCustomDevelopment</test1>
    ;     </custom-fields>
    ; </department>
    ; 
    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf
    CkXml::setCkTag(xml, "department")
    CkXml::ckUpdateChildContent(xml,"name","Coupa Development")
    CkXml::ckUpdateChildContent(xml,"active","true")
    CkXml::ckUpdateChildContent(xml,"custom-fields|test1","TestCustomDevelopment")
    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")
    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf
    CkXml::ckGetXmlSb(xml,sbRequestBody)
    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf
    success = CkHttp::ckHttpSb(http,"POST","https://domain.com/departments?fields=[" + Chr(34) + "id" + Chr(34) + "," + Chr(34) + "name" + Chr(34) + "," + Chr(34) + "active" + Chr(34) + ",{" + Chr(34) + "custom_fields" + Chr(34) + ":{}}]",sbRequestBody,"utf-8","application/xml",resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkXml::ckDispose(xml)
        CkStringBuilder::ckDispose(sbRequestBody)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf
    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttp::ckDispose(http)
    CkXml::ckDispose(xml)
    CkStringBuilder::ckDispose(sbRequestBody)
    CkHttpResponse::ckDispose(resp)
    ProcedureReturn
EndProcedure
        Curl Command
        curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<department>
    <name>Coupa Development</name>
    <active>true</active>
    <custom-fields>
        <test1>TestCustomDevelopment</test1>
    </custom-fields>
</department>'
https://domain.com/departments?fields=["id","name","active",{"custom_fields":{}}]
        Postman Collection Item JSON
        {
  "name": "Create Department",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<department>\n    <name>Coupa Development</name>\n    <active>true</active>\n    <custom-fields>\n        <test1>TestCustomDevelopment</test1>\n    </custom-fields>\n</department>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/departments?fields=[\"id\",\"name\",\"active\",{\"custom_fields\":{}}]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "departments"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\",\"name\",\"active\",{\"custom_fields\":{}}]"
        }
      ]
    }
  },
  "response": [
  ]
}