Chilkat Online Tools

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

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
xml: HCkXml;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;

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

http := CkHttp_Create();

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

xml := CkXml_Create();
CkXml_putTag(xml,'supplier');
CkXml_UpdateChildContent(xml,'name','Coupa Supplier 1');
CkXml_UpdateChildContent(xml,'display-name','Coupa Supplier 1');
CkXml_UpdateChildContent(xml,'number','supplier1#');
CkXml_UpdateChildContent(xml,'status','active');
CkXml_UpdateChildContent(xml,'po-method','email');
CkXml_UpdateChildContent(xml,'po-change-method','email');
CkXml_UpdateChildContent(xml,'default-locale','en');
CkXml_UpdateChildContent(xml,'payment-method','invoice');
CkXml_UpdateChildContent(xml,'po-email','coupasupplier@coupa.com');
CkXml_UpdateChildContent(xml,'invoice-matching-level','3-way');
CkXml_UpdateChildContent(xml,'primary-contact|email','coupasupplierprimarycontact@gmail.com');
CkXml_UpdateChildContent(xml,'primary-contact|name-given','Coupa Supplier Name');
CkXml_UpdateChildContent(xml,'primary-contact|name-family','Coupa Supplier Family Name');
CkXml_UpdateChildContent(xml,'primary-address|name','Coupa Supplier Name');
CkXml_UpdateChildContent(xml,'primary-address|street1','Test Street');
CkXml_UpdateChildContent(xml,'primary-address|city','Test City');
CkXml_UpdateChildContent(xml,'primary-address|state','NC');
CkXml_UpdateChildContentInt(xml,'primary-address|postal-code',27560);
CkXml_UpdateChildContent(xml,'primary-address|country|code','US');
CkXml_UpdateChildContent(xml,'enterprise|code','GLOBAL');
CkXml_UpdateChildContent(xml,'payment-term|code','2/20 Net 30');
CkXml_UpdateAttrAt(xml,'content-groups',True,'type','array');
CkXml_UpdateChildContent(xml,'content-groups|content-group|name','IT');
CkXml_UpdateAttrAt(xml,'supplier-addresses',True,'type','array');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address|name','Coupa Supplier Address 1');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address|street1','Test Street');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address|city','Test City');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address|state','NC');
CkXml_UpdateChildContentInt(xml,'supplier-addresses|supplier-address|postal-code',27560);
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address|country|code','US');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address[1]|name','Coupa Supplier Address 2');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address[1]|street1','Test Street');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address[1]|city','Test City');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address[1]|state','NC');
CkXml_UpdateChildContentInt(xml,'supplier-addresses|supplier-address[1]|postal-code',27560);
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address[1]|country|code','US');
CkXml_UpdateAttrAt(xml,'supplier-addresses|supplier-address[1]|purposes',True,'type','array');
CkXml_UpdateChildContent(xml,'supplier-addresses|supplier-address[1]|purposes|purpose|name','other_address');
CkXml_UpdateAttrAt(xml,'contacts',True,'type','array');
CkXml_UpdateChildContent(xml,'contacts|contact|email','coupasupplierprimarycontact@gmail.com');
CkXml_UpdateChildContent(xml,'contacts|contact|name-given','Coupa Supplier Name');
CkXml_UpdateChildContent(xml,'contacts|contact|name-family','Coupa Supplier Family Name');
CkXml_UpdateChildContent(xml,'diversities|diversity|diversity-category|code','WBE');
CkXml_UpdateChildContent(xml,'diversities|diversity|diversity-category|category','Woman Owned Business Enterprise');
CkXml_UpdateChildContent(xml,'diversities|diversity|country|code','US');

// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');

sbRequestBody := CkStringBuilder_Create();
CkXml_GetXmlSb(xml,sbRequestBody);

resp := CkHttp_PTextSb(http,'POST','https://domain.com/suppliers?fields=["id"]',sbRequestBody,'utf-8','application/xml',False,False);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkXml_Dispose(xml);
CkStringBuilder_Dispose(sbRequestBody);

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