Chilkat Online Tools

PureBasic / Coupa Postman Collection - OAuth - Master / Update Existing Payment Term

Back to Collection Items

IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkXml.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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"?>
    ; <payment-term>
    ;     <active>false</active>
    ; </payment-term>
    ; 

    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkXml::setCkTag(xml, "payment-term")
    CkXml::ckUpdateChildContent(xml,"active","false")

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkXml::ckGetXmlSb(xml,sbRequestBody)

    resp.i = CkHttp::ckPTextSb(http,"PUT","https://domain.com/payment_terms/:id?fields=[" + Chr(34) + "id" + Chr(34) + "," + Chr(34) + "code" + Chr(34) + "," + Chr(34) + "description" + Chr(34) + "," + Chr(34) + "active" + Chr(34) + "]",sbRequestBody,"utf-8","application/xml",0,0)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkXml::ckDispose(xml)
        CkStringBuilder::ckDispose(sbRequestBody)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkXml::ckDispose(xml)
    CkStringBuilder::ckDispose(sbRequestBody)


    ProcedureReturn
EndProcedure

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '<payment-term>
    <active>false</active>
</payment-term>'
https://domain.com/payment_terms/:id?fields=["id","code","description","active"]

Postman Collection Item JSON

{
  "name": "Update Existing Payment Term",
  "request": {
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<payment-term>\n    <active>false</active>\n</payment-term>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/payment_terms/:id?fields=[\"id\",\"code\",\"description\",\"active\"]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "payment_terms",
        ":id"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\",\"code\",\"description\",\"active\"]"
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "32"
        }
      ]
    }
  },
  "response": [
  ]
}