Chilkat Online Tools

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

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"?>
    // <supplier>
    //     <name>Coupa Supplier 1</name>
    //     <display-name>Coupa Supplier 1</display-name>
    //     <number>supplier1#</number>
    //     <status>active</status>
    //     <po-method>email</po-method>
    //     <po-change-method>email</po-change-method>
    //     <default-locale>en</default-locale>
    //     <payment-method>invoice</payment-method>
    //     <po-email>coupasupplier@coupa.com</po-email>
    //     <invoice-matching-level>3-way</invoice-matching-level>
    //     <primary-contact>
    //         <email>coupasupplierprimarycontact@gmail.com</email>
    //         <name-given>Coupa Supplier Name</name-given>
    //         <name-family>Coupa Supplier Family Name</name-family>
    //     </primary-contact>
    //     <primary-address>
    //         <name>Coupa Supplier Name</name>
    //         <street1>Test Street</street1>
    //         <city>Test City</city>
    //         <state>NC</state>
    //         <postal-code>27560</postal-code>
    //         <country>
    //             <code>US</code>
    //         </country>
    //     </primary-address>
    //     <enterprise>
    //         <code>GLOBAL</code>
    //     </enterprise>
    //     <payment-term>
    //         <code>2/20 Net 30</code>
    //     </payment-term>
    //     <content-groups type="array">
    //         <content-group>
    //             <name>IT</name>
    //         </content-group>
    //     </content-groups>
    //     <supplier-addresses type="array">
    //         <supplier-address>
    //             <name>Coupa Supplier Address 1</name>
    //             <street1>Test Street</street1>
    //             <city>Test City</city>
    //             <state>NC</state>
    //             <postal-code>27560</postal-code>
    //             <country>
    //                 <code>US</code>
    //             </country>
    //         </supplier-address>
    //         <supplier-address>
    //             <name>Coupa Supplier Address 2</name>
    //             <street1>Test Street</street1>
    //             <city>Test City</city>
    //             <state>NC</state>
    //             <postal-code>27560</postal-code>
    //             <country>
    //                 <code>US</code>
    //             </country>
    //             <purposes type="array">
    //                 <purpose>
    //                     <name>other_address</name>
    //                 </purpose>
    //             </purposes>
    //         </supplier-address>
    //     </supplier-addresses>
    //     <contacts type="array">
    //         <contact>
    //             <email>coupasupplierprimarycontact@gmail.com</email>
    //             <name-given>Coupa Supplier Name</name-given>
    //             <name-family>Coupa Supplier Family Name</name-family>
    //         </contact>
    //     </contacts>
    //     <diversities>
    //         <diversity>
    //             <diversity-category>
    //                 <code>WBE</code>
    //                 <category>Woman Owned Business Enterprise</category>
    //             </diversity-category>
    //             <country>
    //                 <code>US</code>
    //             </country>
    //         </diversity>
    //     </diversities>
    // </supplier>
    // 

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Set ComTag Of hoXml To "supplier"
    Send ComUpdateChildContent To hoXml "name" "Coupa Supplier 1"
    Send ComUpdateChildContent To hoXml "display-name" "Coupa Supplier 1"
    Send ComUpdateChildContent To hoXml "number" "supplier1#"
    Send ComUpdateChildContent To hoXml "status" "active"
    Send ComUpdateChildContent To hoXml "po-method" "email"
    Send ComUpdateChildContent To hoXml "po-change-method" "email"
    Send ComUpdateChildContent To hoXml "default-locale" "en"
    Send ComUpdateChildContent To hoXml "payment-method" "invoice"
    Send ComUpdateChildContent To hoXml "po-email" "coupasupplier@coupa.com"
    Send ComUpdateChildContent To hoXml "invoice-matching-level" "3-way"
    Send ComUpdateChildContent To hoXml "primary-contact|email" "coupasupplierprimarycontact@gmail.com"
    Send ComUpdateChildContent To hoXml "primary-contact|name-given" "Coupa Supplier Name"
    Send ComUpdateChildContent To hoXml "primary-contact|name-family" "Coupa Supplier Family Name"
    Send ComUpdateChildContent To hoXml "primary-address|name" "Coupa Supplier Name"
    Send ComUpdateChildContent To hoXml "primary-address|street1" "Test Street"
    Send ComUpdateChildContent To hoXml "primary-address|city" "Test City"
    Send ComUpdateChildContent To hoXml "primary-address|state" "NC"
    Send ComUpdateChildContentInt To hoXml "primary-address|postal-code" 27560
    Send ComUpdateChildContent To hoXml "primary-address|country|code" "US"
    Send ComUpdateChildContent To hoXml "enterprise|code" "GLOBAL"
    Send ComUpdateChildContent To hoXml "payment-term|code" "2/20 Net 30"
    Get ComUpdateAttrAt Of hoXml "content-groups" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "content-groups|content-group|name" "IT"
    Get ComUpdateAttrAt Of hoXml "supplier-addresses" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address|name" "Coupa Supplier Address 1"
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address|street1" "Test Street"
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address|city" "Test City"
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address|state" "NC"
    Send ComUpdateChildContentInt To hoXml "supplier-addresses|supplier-address|postal-code" 27560
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address|country|code" "US"
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address[1]|name" "Coupa Supplier Address 2"
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address[1]|street1" "Test Street"
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address[1]|city" "Test City"
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address[1]|state" "NC"
    Send ComUpdateChildContentInt To hoXml "supplier-addresses|supplier-address[1]|postal-code" 27560
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address[1]|country|code" "US"
    Get ComUpdateAttrAt Of hoXml "supplier-addresses|supplier-address[1]|purposes" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "supplier-addresses|supplier-address[1]|purposes|purpose|name" "other_address"
    Get ComUpdateAttrAt Of hoXml "contacts" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "contacts|contact|email" "coupasupplierprimarycontact@gmail.com"
    Send ComUpdateChildContent To hoXml "contacts|contact|name-given" "Coupa Supplier Name"
    Send ComUpdateChildContent To hoXml "contacts|contact|name-family" "Coupa Supplier Family Name"
    Send ComUpdateChildContent To hoXml "diversities|diversity|diversity-category|code" "WBE"
    Send ComUpdateChildContent To hoXml "diversities|diversity|diversity-category|category" "Woman Owned Business Enterprise"
    Send ComUpdateChildContent To hoXml "diversities|diversity|country|code" "US"

    // 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/suppliers?fields=["id"]' 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 '<supplier>
    <name>Coupa Supplier 1</name>
    <display-name>Coupa Supplier 1</display-name>
    <number>supplier1#</number>
    <status>active</status>
    <po-method>email</po-method>
    <po-change-method>email</po-change-method>
    <default-locale>en</default-locale>
    <payment-method>invoice</payment-method>
    <po-email>coupasupplier@coupa.com</po-email>
    <invoice-matching-level>3-way</invoice-matching-level>
    <primary-contact>
        <email>coupasupplierprimarycontact@gmail.com</email>
        <name-given>Coupa Supplier Name</name-given>
        <name-family>Coupa Supplier Family Name</name-family>
    </primary-contact>
    <primary-address>
        <name>Coupa Supplier Name</name>
        <street1>Test Street</street1>
        <city>Test City</city>
        <state>NC</state>
        <postal-code>27560</postal-code>
        <country>
            <code>US</code>
        </country>
    </primary-address>
    <enterprise>
        <code>GLOBAL</code>
    </enterprise>
    <payment-term>
        <code>2/20 Net 30</code>
    </payment-term>
    <content-groups type="array">
        <content-group>
            <name>IT</name>
        </content-group>
    </content-groups>
    <supplier-addresses type="array">
        <supplier-address>
            <name>Coupa Supplier Address 1</name>
            <street1>Test Street</street1>
            <city>Test City</city>
            <state>NC</state>
            <postal-code>27560</postal-code>
            <country>
                <code>US</code>
            </country>
        </supplier-address>
        <supplier-address>
            <name>Coupa Supplier Address 2</name>
            <street1>Test Street</street1>
            <city>Test City</city>
            <state>NC</state>
            <postal-code>27560</postal-code>
            <country>
                <code>US</code>
            </country>
            <purposes type="array">
                <purpose>
                    <name>other_address</name>
                </purpose>
            </purposes>
        </supplier-address>
    </supplier-addresses>
    <contacts type="array">
        <contact>
            <email>coupasupplierprimarycontact@gmail.com</email>
            <name-given>Coupa Supplier Name</name-given>
            <name-family>Coupa Supplier Family Name</name-family>
        </contact>
    </contacts>
    <diversities>
      <diversity>
         <diversity-category>
            <code>WBE</code>
            <category>Woman Owned Business Enterprise</category>
         </diversity-category>
         <country>
            <code>US</code>
         </country>
      </diversity>
   </diversities>
</supplier>'
https://domain.com/suppliers?fields=["id"]

Postman Collection Item JSON

{
  "name": "Create a supplier",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<supplier>\n    <name>Coupa Supplier 1</name>\n    <display-name>Coupa Supplier 1</display-name>\n    <number>supplier1#</number>\n    <status>active</status>\n    <po-method>email</po-method>\n    <po-change-method>email</po-change-method>\n    <default-locale>en</default-locale>\n    <payment-method>invoice</payment-method>\n    <po-email>coupasupplier@coupa.com</po-email>\n    <invoice-matching-level>3-way</invoice-matching-level>\n    <primary-contact>\n        <email>coupasupplierprimarycontact@gmail.com</email>\n        <name-given>Coupa Supplier Name</name-given>\n        <name-family>Coupa Supplier Family Name</name-family>\n    </primary-contact>\n    <primary-address>\n        <name>Coupa Supplier Name</name>\n        <street1>Test Street</street1>\n        <city>Test City</city>\n        <state>NC</state>\n        <postal-code>27560</postal-code>\n        <country>\n            <code>US</code>\n        </country>\n    </primary-address>\n    <enterprise>\n        <code>GLOBAL</code>\n    </enterprise>\n    <payment-term>\n        <code>2/20 Net 30</code>\n    </payment-term>\n    <content-groups type=\"array\">\n        <content-group>\n            <name>IT</name>\n        </content-group>\n    </content-groups>\n    <supplier-addresses type=\"array\">\n        <supplier-address>\n            <name>Coupa Supplier Address 1</name>\n            <street1>Test Street</street1>\n            <city>Test City</city>\n            <state>NC</state>\n            <postal-code>27560</postal-code>\n            <country>\n                <code>US</code>\n            </country>\n        </supplier-address>\n        <supplier-address>\n            <name>Coupa Supplier Address 2</name>\n            <street1>Test Street</street1>\n            <city>Test City</city>\n            <state>NC</state>\n            <postal-code>27560</postal-code>\n            <country>\n                <code>US</code>\n            </country>\n            <purposes type=\"array\">\n                <purpose>\n                    <name>other_address</name>\n                </purpose>\n            </purposes>\n        </supplier-address>\n    </supplier-addresses>\n    <contacts type=\"array\">\n        <contact>\n            <email>coupasupplierprimarycontact@gmail.com</email>\n            <name-given>Coupa Supplier Name</name-given>\n            <name-family>Coupa Supplier Family Name</name-family>\n        </contact>\n    </contacts>\n    <diversities>\n      <diversity>\n         <diversity-category>\n            <code>WBE</code>\n            <category>Woman Owned Business Enterprise</category>\n         </diversity-category>\n         <country>\n            <code>US</code>\n         </country>\n      </diversity>\n   </diversities>\n</supplier>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/suppliers?fields=[\"id\"]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "suppliers"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\"]"
        }
      ]
    }
  },
  "response": [
  ]
}