Chilkat Online Tools

Swift / Coupa Postman Collection - OAuth - Master / Create a supplier in Draft

Back to Collection Items

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

    let http = CkoHttp()
    var success: Bool

    // 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 Draft</name>
    //     <display-name>Coupa Supplier</display-name>
    //     <number/>
    //     <status>draft</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>
    // 

    let xml = CkoXml()
    xml.Tag = "supplier"
    xml.UpdateChildContent("name", value: "Coupa Supplier Draft")
    xml.UpdateChildContent("display-name", value: "Coupa Supplier")
    xml.UpdateChildContent("number", value: "")
    xml.UpdateChildContent("status", value: "draft")
    xml.UpdateChildContent("po-method", value: "email")
    xml.UpdateChildContent("po-change-method", value: "email")
    xml.UpdateChildContent("default-locale", value: "en")
    xml.UpdateChildContent("payment-method", value: "invoice")
    xml.UpdateChildContent("po-email", value: "coupasupplier@coupa.com")
    xml.UpdateChildContent("invoice-matching-level", value: "3-way")
    xml.UpdateChildContent("primary-contact|email", value: "coupasupplierprimarycontact@gmail.com")
    xml.UpdateChildContent("primary-contact|name-given", value: "Coupa Supplier Name")
    xml.UpdateChildContent("primary-contact|name-family", value: "Coupa Supplier Family Name")
    xml.UpdateChildContent("primary-address|name", value: "Coupa Supplier Name")
    xml.UpdateChildContent("primary-address|street1", value: "Test Street")
    xml.UpdateChildContent("primary-address|city", value: "Test City")
    xml.UpdateChildContent("primary-address|state", value: "NC")
    xml.UpdateChildContentInt("primary-address|postal-code", value: 27560)
    xml.UpdateChildContent("primary-address|country|code", value: "US")
    xml.UpdateChildContent("enterprise|code", value: "GLOBAL")
    xml.UpdateChildContent("payment-term|code", value: "2/20 Net 30")
    xml.UpdateAttrAt("content-groups", autoCreate: true, attrName: "type", attrValue: "array")
    xml.UpdateChildContent("content-groups|content-group|name", value: "IT")
    xml.UpdateAttrAt("supplier-addresses", autoCreate: true, attrName: "type", attrValue: "array")
    xml.UpdateChildContent("supplier-addresses|supplier-address|name", value: "Coupa Supplier Address 1")
    xml.UpdateChildContent("supplier-addresses|supplier-address|street1", value: "Test Street")
    xml.UpdateChildContent("supplier-addresses|supplier-address|city", value: "Test City")
    xml.UpdateChildContent("supplier-addresses|supplier-address|state", value: "NC")
    xml.UpdateChildContentInt("supplier-addresses|supplier-address|postal-code", value: 27560)
    xml.UpdateChildContent("supplier-addresses|supplier-address|country|code", value: "US")
    xml.UpdateChildContent("supplier-addresses|supplier-address[1]|name", value: "Coupa Supplier Address 2")
    xml.UpdateChildContent("supplier-addresses|supplier-address[1]|street1", value: "Test Street")
    xml.UpdateChildContent("supplier-addresses|supplier-address[1]|city", value: "Test City")
    xml.UpdateChildContent("supplier-addresses|supplier-address[1]|state", value: "NC")
    xml.UpdateChildContentInt("supplier-addresses|supplier-address[1]|postal-code", value: 27560)
    xml.UpdateChildContent("supplier-addresses|supplier-address[1]|country|code", value: "US")
    xml.UpdateAttrAt("supplier-addresses|supplier-address[1]|purposes", autoCreate: true, attrName: "type", attrValue: "array")
    xml.UpdateChildContent("supplier-addresses|supplier-address[1]|purposes|purpose|name", value: "other_address")
    xml.UpdateAttrAt("contacts", autoCreate: true, attrName: "type", attrValue: "array")
    xml.UpdateChildContent("contacts|contact|email", value: "coupasupplierprimarycontact@gmail.com")
    xml.UpdateChildContent("contacts|contact|name-given", value: "Coupa Supplier Name")
    xml.UpdateChildContent("contacts|contact|name-family", value: "Coupa Supplier Family Name")
    xml.UpdateChildContent("diversities|diversity|diversity-category|code", value: "WBE")
    xml.UpdateChildContent("diversities|diversity|diversity-category|category", value: "Woman Owned Business Enterprise")
    xml.UpdateChildContent("diversities|diversity|country|code", value: "US")

    // Adds the "Authorization: Bearer <access_token>" header.
    http.AuthToken = "<access_token>"

    let sbRequestBody = CkoStringBuilder()
    xml.GetXmlSb(sbRequestBody)

    var resp: CkoHttpResponse? = http.PTextSb("POST", url: "https://domain.com/suppliers?fields=[\"id\"]", textData: sbRequestBody, charset: "utf-8", contentType: "application/xml", md5: false, gzip: false)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    print("\(resp!.StatusCode.intValue)")
    print("\(resp!.BodyStr)")
    resp = nil

}

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<supplier>
    <name>Coupa Supplier Draft</name>
    <display-name>Coupa Supplier</display-name>
    <number></number>
    <status>draft</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 in Draft",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<supplier>\n    <name>Coupa Supplier Draft</name>\n    <display-name>Coupa Supplier</display-name>\n    <number></number>\n    <status>draft</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": [
  ]
}