Chilkat Online Tools

VBScript / Coupa Postman Collection - OAuth - Master / Add contract term

Back to Collection Items

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

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

set http = CreateObject("Chilkat_9_5_0.Http")

' 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"?>
' <contract-term>
'     <name>API Contract Term 1</name>
'     <contract-term-type>PriceRangeContractTerm</contract-term-type>
'     <use-pct-discounts type="boolean">true</use-pct-discounts>
'     <tier-1-upper-bound type="decimal">15.0</tier-1-upper-bound>
'     <tier-1-disc-pct type="decimal">6.0</tier-1-disc-pct>
'     <tier-2-disc-pct type="decimal">7.0</tier-2-disc-pct>
' </contract-term>
' 

set xml = CreateObject("Chilkat_9_5_0.Xml")
xml.Tag = "contract-term"
xml.UpdateChildContent "name","API Contract Term 1"
xml.UpdateChildContent "contract-term-type","PriceRangeContractTerm"
success = xml.UpdateAttrAt("use-pct-discounts",1,"type","boolean")
xml.UpdateChildContent "use-pct-discounts","true"
success = xml.UpdateAttrAt("tier-1-upper-bound",1,"type","decimal")
xml.UpdateChildContent "tier-1-upper-bound","15.0"
success = xml.UpdateAttrAt("tier-1-disc-pct",1,"type","decimal")
xml.UpdateChildContent "tier-1-disc-pct","6.0"
success = xml.UpdateAttrAt("tier-2-disc-pct",1,"type","decimal")
xml.UpdateChildContent "tier-2-disc-pct","7.0"

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

set sbRequestBody = CreateObject("Chilkat_9_5_0.StringBuilder")
success = xml.GetXmlSb(sbRequestBody)

' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.PTextSb("POST","https://domain.com/contracts/:id/contract_terms",sbRequestBody,"utf-8","application/xml",0,0)
If (http.LastMethodSuccess = 0) Then
    outFile.WriteLine(http.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine(resp.StatusCode)
outFile.WriteLine(resp.BodyStr)


outFile.Close

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<?xml version="1.0" encoding="UTF-8"?>
<contract-term>
    <name>API Contract Term 1</name>
    <contract-term-type>PriceRangeContractTerm</contract-term-type>
    <use-pct-discounts type="boolean">true</use-pct-discounts>
    <tier-1-upper-bound type="decimal">15.0</tier-1-upper-bound>
    <tier-1-disc-pct type="decimal">6.0</tier-1-disc-pct>
    <tier-2-disc-pct type="decimal">7.0</tier-2-disc-pct>
</contract-term>'
https://domain.com/contracts/:id/contract_terms

Postman Collection Item JSON

{
  "name": "Add contract term",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<contract-term>\n    <name>API Contract Term 1</name>\n    <contract-term-type>PriceRangeContractTerm</contract-term-type>\n    <use-pct-discounts type=\"boolean\">true</use-pct-discounts>\n    <tier-1-upper-bound type=\"decimal\">15.0</tier-1-upper-bound>\n    <tier-1-disc-pct type=\"decimal\">6.0</tier-1-disc-pct>\n    <tier-2-disc-pct type=\"decimal\">7.0</tier-2-disc-pct>\n</contract-term>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/contracts/:id/contract_terms",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "contracts",
        ":id",
        "contract_terms"
      ],
      "variable": [
        {
          "key": "id",
          "value": "377",
          "type": "string"
        }
      ]
    }
  },
  "response": [
  ]
}