Chilkat Online Tools

DataFlex / Coupa Postman Collection - OAuth - Master / Create a Contract

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoXml
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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>
    // 

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Set ComTag Of hoXml To "contract"
    Send ComUpdateChildContent To hoXml "name" "Test API Contract 159753"
    Send ComUpdateChildContentInt To hoXml "number" 159753
    Send ComUpdateChildContent To hoXml "type" "Equipment Lease"
    Get ComUpdateAttrAt Of hoXml "version" True "type" "integer" To iSuccess
    Send ComUpdateChildContentInt To hoXml "version" 1
    Get ComUpdateAttrAt Of hoXml "start-date" True "type" "dateTime" To iSuccess
    Send ComUpdateChildContent To hoXml "start-date" "2021-12-20T00:00:00+05:30"
    Get ComUpdateAttrAt Of hoXml "end-date" True "type" "dateTime" To iSuccess
    Send ComUpdateChildContent To hoXml "end-date" "2022-12-20T00:00:00+05:30"
    Send ComUpdateChildContent To hoXml "status" "draft"
    Get ComUpdateAttrAt Of hoXml "minimum-value" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "minimum-value" "100.00"
    Get ComUpdateAttrAt Of hoXml "maximum-value" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "maximum-value" "2000.00"
    Send ComUpdateChildContent To hoXml "stop-spend-based-on-max-value" "Yes"
    Send ComUpdateChildContent To hoXml "terms" "Annual"
    Send ComUpdateChildContentInt To hoXml "savings-pct" 10
    Get ComUpdateAttrAt Of hoXml "supplier-invoiceable" True "type" "boolean" To iSuccess
    Send ComUpdateChildContent To hoXml "supplier-invoiceable" "true"
    Get ComUpdateAttrAt Of hoXml "is-default" True "type" "boolean" To iSuccess
    Send ComUpdateChildContent To hoXml "is-default" "true"
    Get ComUpdateAttrAt Of hoXml "preferred" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "min-commit" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "min-commit" "0.00"
    Get ComUpdateAttrAt Of hoXml "max-commit" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "max-commit" "0.00"
    Send ComUpdateChildContent To hoXml "supplier-account" ""
    Get ComUpdateAttrAt Of hoXml "use-order-windows" True "type" "boolean" To iSuccess
    Send ComUpdateChildContent To hoXml "use-order-windows" "false"
    Send ComUpdateChildContent To hoXml "order-window-tz" "Asia/Kolkata"
    Send ComUpdateChildContent To hoXml "requisition-message" ""
    Send ComUpdateChildContent To hoXml "po-message" ""
    Get ComUpdateAttrAt Of hoXml "legal-agreement-url" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "current-approval" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "used-for-buying" True "type" "boolean" To iSuccess
    Send ComUpdateChildContent To hoXml "used-for-buying" "true"
    Get ComUpdateAttrAt Of hoXml "strict-invoicing-rules" True "type" "boolean" To iSuccess
    Send ComUpdateChildContent To hoXml "strict-invoicing-rules" "false"
    Get ComUpdateAttrAt Of hoXml "term-type" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "auto-extend-end-date-for-renewal" True "type" "boolean" To iSuccess
    Send ComUpdateChildContent To hoXml "auto-extend-end-date-for-renewal" "false"
    Get ComUpdateAttrAt Of hoXml "terminated" True "type" "boolean" To iSuccess
    Send ComUpdateChildContent To hoXml "terminated" "false"
    Get ComUpdateAttrAt Of hoXml "termination-notice" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "termination-notice-length-unit" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "termination-notice-length-value" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "consent" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "no-of-renewals" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "renewal-length-unit" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "renewal-length-value" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "length-of-notice-unit" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "length-of-notice-value" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "source-id" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "source-type" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "source" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "amended-contract-type" True "nil" "true" To iSuccess
    Get ComUpdateAttrAt Of hoXml "quote-response-id" True "nil" "true" To iSuccess
    Send ComUpdateChildContent To hoXml "description" ""
    Get ComUpdateAttrAt Of hoXml "execution-date" True "nil" "true" To iSuccess
    Send ComUpdateChildContentInt To hoXml "supplier|number" 123456
    Send ComUpdateChildContent To hoXml "currency|code" "USD"
    Get ComUpdateAttrAt Of hoXml "content-groups" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "content-groups|content-group|name" "Everyone"
    Get ComUpdateAttrAt Of hoXml "reason-insight-events" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "schedule|day0" "anytime"
    Send ComUpdateChildContent To hoXml "schedule|day1" "anytime"
    Send ComUpdateChildContent To hoXml "schedule|day2" "anytime"
    Send ComUpdateChildContent To hoXml "schedule|day3" "anytime"
    Send ComUpdateChildContent To hoXml "schedule|day4" "anytime"
    Send ComUpdateChildContent To hoXml "schedule|day5" "anytime"
    Send ComUpdateChildContent To hoXml "schedule|day6" "anytime"
    Get ComUpdateAttrAt Of hoXml "contract-terms" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "submitter|login" "coupasam"
    Get ComUpdateAttrAt Of hoXml "tags" True "type" "array" To iSuccess
    Get ComUpdateAttrAt Of hoXml "taggings" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "contract-owner|login" "coupasam"

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComGetXmlSb Of hoXml vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "POST" "https://domain.com/contracts/" vSbRequestBody "utf-8" "application/xml" False False To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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": [
  ]
}