Chilkat Online Tools

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

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkXmlW xml;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

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

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

    sbRequestBody = CkStringBuilderW_Create();
    CkXmlW_GetXmlSb(xml,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"POST",L"https://domain.com/suppliers?fields=[\"id\"]",sbRequestBody,L"utf-8",L"application/xml",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkXmlW_Dispose(xml);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkXmlW_Dispose(xml);
    CkStringBuilderW_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": [
  ]
}