Chilkat Online Tools

unicodeC / Coupa Postman Collection - OAuth - Master / Create A User

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"?>
    // <user>
    //     <login>coupasam1</login>
    //     <email>coupasam1@coupa.com</email>
    //     <firstname>Coupa</firstname>
    //     <lastname>Sam 1</lastname>
    //     <fullname>Coupa Sam 1</fullname>
    //     <purchasing-user>true</purchasing-user>
    //     <expense-user>false</expense-user>
    //     <sourcing-user>false</sourcing-user>
    //     <inventory-user>false</inventory-user>
    //     <contracts-user>false</contracts-user>
    //     <analytics-user>false</analytics-user>
    //     <aic-user>false</aic-user>
    //     <spend-guard-user>false</spend-guard-user>
    //     <ccw-user>false</ccw-user>
    //     <clm-advanced-user>false</clm-advanced-user>
    //     <supply-chain-user>false</supply-chain-user>
    //     <risk-assess-user>false</risk-assess-user>
    //     <employee-number>123456789</employee-number>
    //     <active>true</active>
    //     <account-security-type>0</account-security-type>
    //     <authentication-method>saml</authentication-method>
    //     <sso-identifier>coupasam1@coupa.com</sso-identifier>
    //     <default-locale nil="true"/>
    //     <business-group-security-type>1</business-group-security-type>
    //     <edit-invoice-on-quick-entry>false</edit-invoice-on-quick-entry>
    //     <avatar-thumb-url nil="true"/>
    //     <mention-name>coupasam1</mention-name>
    //     <seniority-level nil="true"/>
    //     <business-function nil="true"/>
    //     <employee-payment-channel>ERP</employee-payment-channel>
    //     <allow-employee-payment-account-creation>false</allow-employee-payment-account-creation>
    //     <rank/>
    //     <default-cost-center/>
    //     <phone-work>
    //         <country-code>1</country-code>
    //         <area-code>650</area-code>
    //         <number>5856306</number>
    //         <extension nil="true"/>
    //     </phone-work>
    //     <roles>
    //         <role>
    //             <name>User</name>
    //         </role>
    //         <role>
    //             <name>Central Receiving</name>
    //         </role>
    //         <role>
    //             <name>Edit Requisition as Approver</name>
    //         </role>
    //         <role>
    //             <name>Dashboard</name>
    //         </role>
    //         <role>
    //             <name>Split Accounting</name>
    //         </role>
    //     </roles>
    //     <manager>
    //         <login>mjordan</login>
    //     </manager>
    //     <default-account>
    //         <code>SF-Finance-Indirect</code>
    //         <segment-1>SF</segment-1>
    //         <segment-2>Finance</segment-2>
    //         <segment-3>Indirect</segment-3>
    //         <account-type>
    //             <name>ERP 1</name>
    //             <currency>
    //                 <code>USD</code>
    //             </currency>
    //         </account-type>
    //     </default-account>
    //     <default-account-type>
    //         <name>ERP 1</name>
    //         <currency>
    //             <code>USD</code>
    //         </currency>
    //     </default-account-type>
    //     <default-currency>
    //         <code>USD</code>
    //     </default-currency>
    //     <department>
    //         <name>Marketing</name>
    //     </department>
    //     <requisition-approval-limit>
    //         <amount>10000.00</amount>
    //         <currency>
    //             <code>USD</code>
    //         </currency>
    //     </requisition-approval-limit>
    //     <invoice-approval-limit>
    //         <amount>15000.00</amount>
    //         <currency>
    //             <code>USD</code>
    //         </currency>
    //     </invoice-approval-limit>
    //     <requisition-self-approval-limit>
    //         <amount>500.00</amount>
    //         <currency>
    //             <code>USD</code>
    //         </currency>
    //     </requisition-self-approval-limit>
    //     <expenses-delegated-to/>
    //     <can-expense-for/>
    //     <content-groups/>
    //     <account-groups/>
    //     <approval-groups/>
    //     <user-groups/>
    //     <working-warehouses/>
    //     <inventory-organizations/>
    // </user>
    // 

    xml = CkXmlW_Create();
    CkXmlW_putTag(xml,L"user");
    CkXmlW_UpdateChildContent(xml,L"login",L"coupasam1");
    CkXmlW_UpdateChildContent(xml,L"email",L"coupasam1@coupa.com");
    CkXmlW_UpdateChildContent(xml,L"firstname",L"Coupa");
    CkXmlW_UpdateChildContent(xml,L"lastname",L"Sam 1");
    CkXmlW_UpdateChildContent(xml,L"fullname",L"Coupa Sam 1");
    CkXmlW_UpdateChildContent(xml,L"purchasing-user",L"true");
    CkXmlW_UpdateChildContent(xml,L"expense-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"sourcing-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"inventory-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"contracts-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"analytics-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"aic-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"spend-guard-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"ccw-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"clm-advanced-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"supply-chain-user",L"false");
    CkXmlW_UpdateChildContent(xml,L"risk-assess-user",L"false");
    CkXmlW_UpdateChildContentInt(xml,L"employee-number",123456789);
    CkXmlW_UpdateChildContent(xml,L"active",L"true");
    CkXmlW_UpdateChildContentInt(xml,L"account-security-type",0);
    CkXmlW_UpdateChildContent(xml,L"authentication-method",L"saml");
    CkXmlW_UpdateChildContent(xml,L"sso-identifier",L"coupasam1@coupa.com");
    CkXmlW_UpdateAttrAt(xml,L"default-locale",TRUE,L"nil",L"true");
    CkXmlW_UpdateChildContentInt(xml,L"business-group-security-type",1);
    CkXmlW_UpdateChildContent(xml,L"edit-invoice-on-quick-entry",L"false");
    CkXmlW_UpdateAttrAt(xml,L"avatar-thumb-url",TRUE,L"nil",L"true");
    CkXmlW_UpdateChildContent(xml,L"mention-name",L"coupasam1");
    CkXmlW_UpdateAttrAt(xml,L"seniority-level",TRUE,L"nil",L"true");
    CkXmlW_UpdateAttrAt(xml,L"business-function",TRUE,L"nil",L"true");
    CkXmlW_UpdateChildContent(xml,L"employee-payment-channel",L"ERP");
    CkXmlW_UpdateChildContent(xml,L"allow-employee-payment-account-creation",L"false");
    CkXmlW_UpdateChildContent(xml,L"rank",L"");
    CkXmlW_UpdateChildContent(xml,L"default-cost-center",L"");
    CkXmlW_UpdateChildContentInt(xml,L"phone-work|country-code",1);
    CkXmlW_UpdateChildContentInt(xml,L"phone-work|area-code",650);
    CkXmlW_UpdateChildContentInt(xml,L"phone-work|number",5856306);
    CkXmlW_UpdateAttrAt(xml,L"phone-work|extension",TRUE,L"nil",L"true");
    CkXmlW_UpdateChildContent(xml,L"roles|role|name",L"User");
    CkXmlW_UpdateChildContent(xml,L"roles|role[1]|name",L"Central Receiving");
    CkXmlW_UpdateChildContent(xml,L"roles|role[2]|name",L"Edit Requisition as Approver");
    CkXmlW_UpdateChildContent(xml,L"roles|role[3]|name",L"Dashboard");
    CkXmlW_UpdateChildContent(xml,L"roles|role[4]|name",L"Split Accounting");
    CkXmlW_UpdateChildContent(xml,L"manager|login",L"mjordan");
    CkXmlW_UpdateChildContent(xml,L"default-account|code",L"SF-Finance-Indirect");
    CkXmlW_UpdateChildContent(xml,L"default-account|segment-1",L"SF");
    CkXmlW_UpdateChildContent(xml,L"default-account|segment-2",L"Finance");
    CkXmlW_UpdateChildContent(xml,L"default-account|segment-3",L"Indirect");
    CkXmlW_UpdateChildContent(xml,L"default-account|account-type|name",L"ERP 1");
    CkXmlW_UpdateChildContent(xml,L"default-account|account-type|currency|code",L"USD");
    CkXmlW_UpdateChildContent(xml,L"default-account-type|name",L"ERP 1");
    CkXmlW_UpdateChildContent(xml,L"default-account-type|currency|code",L"USD");
    CkXmlW_UpdateChildContent(xml,L"default-currency|code",L"USD");
    CkXmlW_UpdateChildContent(xml,L"department|name",L"Marketing");
    CkXmlW_UpdateChildContent(xml,L"requisition-approval-limit|amount",L"10000.00");
    CkXmlW_UpdateChildContent(xml,L"requisition-approval-limit|currency|code",L"USD");
    CkXmlW_UpdateChildContent(xml,L"invoice-approval-limit|amount",L"15000.00");
    CkXmlW_UpdateChildContent(xml,L"invoice-approval-limit|currency|code",L"USD");
    CkXmlW_UpdateChildContent(xml,L"requisition-self-approval-limit|amount",L"500.00");
    CkXmlW_UpdateChildContent(xml,L"requisition-self-approval-limit|currency|code",L"USD");
    CkXmlW_UpdateChildContent(xml,L"expenses-delegated-to",L"");
    CkXmlW_UpdateChildContent(xml,L"can-expense-for",L"");
    CkXmlW_UpdateChildContent(xml,L"content-groups",L"");
    CkXmlW_UpdateChildContent(xml,L"account-groups",L"");
    CkXmlW_UpdateChildContent(xml,L"approval-groups",L"");
    CkXmlW_UpdateChildContent(xml,L"user-groups",L"");
    CkXmlW_UpdateChildContent(xml,L"working-warehouses",L"");
    CkXmlW_UpdateChildContent(xml,L"inventory-organizations",L"");

    // 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/users?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 '<?xml version="1.0" encoding="UTF-8"?>
<user>
    <login>coupasam1</login>
    <email>coupasam1@coupa.com</email>
    <firstname>Coupa</firstname>
    <lastname>Sam 1</lastname>
    <fullname>Coupa Sam 1</fullname>
    <purchasing-user>true</purchasing-user>
    <expense-user>false</expense-user>
    <sourcing-user>false</sourcing-user>
    <inventory-user>false</inventory-user>
    <contracts-user>false</contracts-user>
    <analytics-user>false</analytics-user>
    <aic-user>false</aic-user>
    <spend-guard-user>false</spend-guard-user>
    <ccw-user>false</ccw-user>
    <clm-advanced-user>false</clm-advanced-user>
    <supply-chain-user>false</supply-chain-user>
    <risk-assess-user>false</risk-assess-user>
    <employee-number>123456789</employee-number>
    <active>true</active>
    <account-security-type>0</account-security-type>
    <authentication-method>saml</authentication-method>
    <sso-identifier>coupasam1@coupa.com</sso-identifier>
    <default-locale nil="true"/>
    <business-group-security-type>1</business-group-security-type>
    <edit-invoice-on-quick-entry>false</edit-invoice-on-quick-entry>
    <avatar-thumb-url nil="true"/>
    <mention-name>coupasam1</mention-name>
    <seniority-level nil="true"/>
    <business-function nil="true"/>
    <employee-payment-channel>ERP</employee-payment-channel>
    <allow-employee-payment-account-creation>false</allow-employee-payment-account-creation>
    <rank></rank>
    <default-cost-center></default-cost-center>
    <phone-work>
        <country-code>1</country-code>
        <area-code>650</area-code>
        <number>5856306</number>
        <extension nil="true"/>
    </phone-work>
    <roles>
        <role>
            <name>User</name>
        </role>
        <role>
            <name>Central Receiving</name>
        </role>
        <role>
            <name>Edit Requisition as Approver</name>
        </role>
        <role>
            <name>Dashboard</name>
        </role>
        <role>
            <name>Split Accounting</name>
        </role>
    </roles>
    <manager>
        <login>mjordan</login>
    </manager>
    <default-account>
        <code>SF-Finance-Indirect</code>
        <segment-1>SF</segment-1>
        <segment-2>Finance</segment-2>
        <segment-3>Indirect</segment-3>
        <account-type>
            <name>ERP 1</name>
            <currency>
                <code>USD</code>
            </currency>
        </account-type>
    </default-account>
    <default-account-type>
        <name>ERP 1</name>
        <currency>
            <code>USD</code>
        </currency>
    </default-account-type>
    <default-currency>
        <code>USD</code>
    </default-currency>
    <department>
        <name>Marketing</name>
    </department>
    <requisition-approval-limit>
        <amount>10000.00</amount>
        <currency>
            <code>USD</code>
        </currency>
    </requisition-approval-limit>
    <invoice-approval-limit>
        <amount>15000.00</amount>
        <currency>
            <code>USD</code>
        </currency>
    </invoice-approval-limit>
    <requisition-self-approval-limit>
        <amount>500.00</amount>
        <currency>
            <code>USD</code>
        </currency>
    </requisition-self-approval-limit>
    <expenses-delegated-to/>
    <can-expense-for/>
    <content-groups/>
    <account-groups/>
    <approval-groups/>
    <user-groups/>
    <working-warehouses/>
    <inventory-organizations/>
</user>'
https://domain.com/users?fields=["id"]

Postman Collection Item JSON

{
  "name": "Create A User",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>\n    <login>coupasam1</login>\n    <email>coupasam1@coupa.com</email>\n    <firstname>Coupa</firstname>\n    <lastname>Sam 1</lastname>\n    <fullname>Coupa Sam 1</fullname>\n    <purchasing-user>true</purchasing-user>\n    <expense-user>false</expense-user>\n    <sourcing-user>false</sourcing-user>\n    <inventory-user>false</inventory-user>\n    <contracts-user>false</contracts-user>\n    <analytics-user>false</analytics-user>\n    <aic-user>false</aic-user>\n    <spend-guard-user>false</spend-guard-user>\n    <ccw-user>false</ccw-user>\n    <clm-advanced-user>false</clm-advanced-user>\n    <supply-chain-user>false</supply-chain-user>\n    <risk-assess-user>false</risk-assess-user>\n    <employee-number>123456789</employee-number>\n    <active>true</active>\n    <account-security-type>0</account-security-type>\n    <authentication-method>saml</authentication-method>\n    <sso-identifier>coupasam1@coupa.com</sso-identifier>\n    <default-locale nil=\"true\"/>\n    <business-group-security-type>1</business-group-security-type>\n    <edit-invoice-on-quick-entry>false</edit-invoice-on-quick-entry>\n    <avatar-thumb-url nil=\"true\"/>\n    <mention-name>coupasam1</mention-name>\n    <seniority-level nil=\"true\"/>\n    <business-function nil=\"true\"/>\n    <employee-payment-channel>ERP</employee-payment-channel>\n    <allow-employee-payment-account-creation>false</allow-employee-payment-account-creation>\n    <rank></rank>\n    <default-cost-center></default-cost-center>\n    <phone-work>\n        <country-code>1</country-code>\n        <area-code>650</area-code>\n        <number>5856306</number>\n        <extension nil=\"true\"/>\n    </phone-work>\n    <roles>\n        <role>\n            <name>User</name>\n        </role>\n        <role>\n            <name>Central Receiving</name>\n        </role>\n        <role>\n            <name>Edit Requisition as Approver</name>\n        </role>\n        <role>\n            <name>Dashboard</name>\n        </role>\n        <role>\n            <name>Split Accounting</name>\n        </role>\n    </roles>\n    <manager>\n        <login>mjordan</login>\n    </manager>\n    <default-account>\n        <code>SF-Finance-Indirect</code>\n        <segment-1>SF</segment-1>\n        <segment-2>Finance</segment-2>\n        <segment-3>Indirect</segment-3>\n        <account-type>\n            <name>ERP 1</name>\n            <currency>\n                <code>USD</code>\n            </currency>\n        </account-type>\n    </default-account>\n    <default-account-type>\n        <name>ERP 1</name>\n        <currency>\n            <code>USD</code>\n        </currency>\n    </default-account-type>\n    <default-currency>\n        <code>USD</code>\n    </default-currency>\n    <department>\n        <name>Marketing</name>\n    </department>\n    <requisition-approval-limit>\n        <amount>10000.00</amount>\n        <currency>\n            <code>USD</code>\n        </currency>\n    </requisition-approval-limit>\n    <invoice-approval-limit>\n        <amount>15000.00</amount>\n        <currency>\n            <code>USD</code>\n        </currency>\n    </invoice-approval-limit>\n    <requisition-self-approval-limit>\n        <amount>500.00</amount>\n        <currency>\n            <code>USD</code>\n        </currency>\n    </requisition-self-approval-limit>\n    <expenses-delegated-to/>\n    <can-expense-for/>\n    <content-groups/>\n    <account-groups/>\n    <approval-groups/>\n    <user-groups/>\n    <working-warehouses/>\n    <inventory-organizations/>\n</user>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/users?fields=[\"id\"]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "users"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\"]"
        }
      ]
    }
  },
  "response": [
  ]
}