Chilkat Online Tools

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

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Xml
oleobject loo_SbRequestBody
oleobject loo_Resp

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_Xml = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

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

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

loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Xml.GetXmlSb(loo_SbRequestBody)

loo_Resp = loo_Http.PTextSb("POST","https://domain.com/users?fields=[~"id~"]",loo_SbRequestBody,"utf-8","application/xml",0,0)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Xml
    destroy loo_SbRequestBody
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Xml
destroy loo_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": [
  ]
}