Chilkat Online Tools

Xojo / Coupa Postman Collection - OAuth - Master / Create a Requisition and Submit the same for approval

Back to Collection Items

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

Dim http As New Chilkat.Http
Dim success As Boolean

// 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"?>
// <requisition-header>
//     <justification>Test</justification>
//     <ship-to-attention>Coupa Buyer</ship-to-attention>
//     <currency>
//         <code>USD</code>
//     </currency>
//     <requested-by>
//         <login>CoupaSam</login>
//         <email>CoupaSam@coupa.com</email>
//     </requested-by>
//     <ship-to-address>
//         <location-code>DUMMYST</location-code>
//     </ship-to-address>
//     <requisition-lines type="array">
//         <requisition-line>
//             <description>Test</description>
//             <line-num type="integer">1</line-num>
//             <total type="decimal">10.00</total>
//             <line-type>RequisitionAmountLine</line-type>
//             <unit-price type="decimal">10.00</unit-price>
//             <need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
//             <account>
//                 <name>Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1</name>
//                 <code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>
//                 <active type="boolean">true</active>
//                 <segment-1>DUM_SEG_1_LV_1</segment-1>
//                 <segment-2>DUM_SEG_2_LV_1</segment-2>
//                 <account-type>
//                     <name>Dummy Chart of Accounts</name>
//                     <currency>
//                         <code>USD</code>
//                     </currency>
//                 </account-type>
//             </account>
//             <currency>
//                 <code>USD</code>
//             </currency>
//             <supplier>
//                 <name>CoupaTester</name>
//                 <number>123456</number>
//             </supplier>
//         </requisition-line>
//     </requisition-lines>
// </requisition-header>
// 

Dim xml As New Chilkat.Xml
xml.Tag = "requisition-header"
xml.UpdateChildContent "justification","Test"
xml.UpdateChildContent "ship-to-attention","Coupa Buyer"
xml.UpdateChildContent "currency|code","USD"
xml.UpdateChildContent "requested-by|login","CoupaSam"
xml.UpdateChildContent "requested-by|email","CoupaSam@coupa.com"
xml.UpdateChildContent "ship-to-address|location-code","DUMMYST"
success = xml.UpdateAttrAt("requisition-lines",True,"type","array")
xml.UpdateChildContent "requisition-lines|requisition-line|description","Test"
success = xml.UpdateAttrAt("requisition-lines|requisition-line|line-num",True,"type","integer")
xml.UpdateChildContentInt "requisition-lines|requisition-line|line-num",1
success = xml.UpdateAttrAt("requisition-lines|requisition-line|total",True,"type","decimal")
xml.UpdateChildContent "requisition-lines|requisition-line|total","10.00"
xml.UpdateChildContent "requisition-lines|requisition-line|line-type","RequisitionAmountLine"
success = xml.UpdateAttrAt("requisition-lines|requisition-line|unit-price",True,"type","decimal")
xml.UpdateChildContent "requisition-lines|requisition-line|unit-price","10.00"
success = xml.UpdateAttrAt("requisition-lines|requisition-line|need-by-date",True,"type","dateTime")
xml.UpdateChildContent "requisition-lines|requisition-line|need-by-date","2020-05-15T00:00:00-05:00"
xml.UpdateChildContent "requisition-lines|requisition-line|account|name","Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1"
xml.UpdateChildContent "requisition-lines|requisition-line|account|code","DUM_SEG_1_LV_1-DUM_SEG_2_LV_1"
success = xml.UpdateAttrAt("requisition-lines|requisition-line|account|active",True,"type","boolean")
xml.UpdateChildContent "requisition-lines|requisition-line|account|active","true"
xml.UpdateChildContent "requisition-lines|requisition-line|account|segment-1","DUM_SEG_1_LV_1"
xml.UpdateChildContent "requisition-lines|requisition-line|account|segment-2","DUM_SEG_2_LV_1"
xml.UpdateChildContent "requisition-lines|requisition-line|account|account-type|name","Dummy Chart of Accounts"
xml.UpdateChildContent "requisition-lines|requisition-line|account|account-type|currency|code","USD"
xml.UpdateChildContent "requisition-lines|requisition-line|currency|code","USD"
xml.UpdateChildContent "requisition-lines|requisition-line|supplier|name","CoupaTester"
xml.UpdateChildContentInt "requisition-lines|requisition-line|supplier|number",123456

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

Dim sbRequestBody As New Chilkat.StringBuilder
success = xml.GetXmlSb(sbRequestBody)

Dim resp As Chilkat.HttpResponse
resp = http.PTextSb("POST","https://domain.com/requisitions/submit_for_approval?fields=[""id""]",sbRequestBody,"utf-8","application/xml",False,False)
If (http.LastMethodSuccess = False) Then
    System.DebugLog(http.LastErrorText)
    Return
End If

System.DebugLog(Str(resp.StatusCode))
System.DebugLog(resp.BodyStr)

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<?xml version="1.0" encoding="UTF-8"?>
<requisition-header>
    <justification>Test</justification>
    <ship-to-attention>Coupa Buyer</ship-to-attention>
    <currency>
        <code>USD</code>
    </currency>
    <requested-by>
        <login>CoupaSam</login>
        <email>CoupaSam@coupa.com</email>
    </requested-by>
    <ship-to-address>
        <location-code>DUMMYST</location-code>
    </ship-to-address>
    <requisition-lines type="array">
        <requisition-line>
            <description>Test</description>
            <line-num type="integer">1</line-num>
            <total type="decimal">10.00</total>
            <line-type>RequisitionAmountLine</line-type>
            <unit-price type="decimal">10.00</unit-price>
            <need-by-date type="dateTime">2020-05-15T00:00:00-05:00</need-by-date>
            <account>
                <name>Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1</name>
                <code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>
                <active type="boolean">true</active>
                <segment-1>DUM_SEG_1_LV_1</segment-1>
                <segment-2>DUM_SEG_2_LV_1</segment-2>
                <account-type>
                    <name>Dummy Chart of Accounts</name>
                    <currency>
                        <code>USD</code>
                    </currency>
                </account-type>
            </account>
            <currency>
                <code>USD</code>
            </currency>
            <supplier>
                <name>CoupaTester</name>
                <number>123456</number>
            </supplier>
        </requisition-line>
    </requisition-lines>
</requisition-header>'
https://domain.com/requisitions/submit_for_approval?fields=["id"]

Postman Collection Item JSON

{
  "name": "Create a Requisition and Submit the same for approval",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<requisition-header>\n    <justification>Test</justification>\n    <ship-to-attention>Coupa Buyer</ship-to-attention>\n    <currency>\n        <code>USD</code>\n    </currency>\n    <requested-by>\n        <login>CoupaSam</login>\n        <email>CoupaSam@coupa.com</email>\n    </requested-by>\n    <ship-to-address>\n        <location-code>DUMMYST</location-code>\n    </ship-to-address>\n    <requisition-lines type=\"array\">\n        <requisition-line>\n            <description>Test</description>\n            <line-num type=\"integer\">1</line-num>\n            <total type=\"decimal\">10.00</total>\n            <line-type>RequisitionAmountLine</line-type>\n            <unit-price type=\"decimal\">10.00</unit-price>\n            <need-by-date type=\"dateTime\">2020-05-15T00:00:00-05:00</need-by-date>\n            <account>\n                <name>Dummy Segment 1 LookupValue 1-Dummy Segment 2 LookupValue 1</name>\n                <code>DUM_SEG_1_LV_1-DUM_SEG_2_LV_1</code>\n                <active type=\"boolean\">true</active>\n                <segment-1>DUM_SEG_1_LV_1</segment-1>\n                <segment-2>DUM_SEG_2_LV_1</segment-2>\n                <account-type>\n                    <name>Dummy Chart of Accounts</name>\n                    <currency>\n                        <code>USD</code>\n                    </currency>\n                </account-type>\n            </account>\n            <currency>\n                <code>USD</code>\n            </currency>\n            <supplier>\n                <name>CoupaTester</name>\n                <number>123456</number>\n            </supplier>\n        </requisition-line>\n    </requisition-lines>\n</requisition-header>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/requisitions/submit_for_approval?fields=[\"id\"]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "requisitions",
        "submit_for_approval"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\"]"
        }
      ]
    }
  },
  "response": [
  ]
}