Chilkat Online Tools

DataFlex / Coupa Postman Collection - OAuth - Master / Create Commodity

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoXml
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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"?>
    // <commodity>
    //     <active>true</active>
    //     <name>Microsoft Services</name>
    //     <category/>
    //     <custom-fields>
    //         <gl-account>0010</gl-account>
    //     </custom-fields>
    // </commodity>
    // 

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Set ComTag Of hoXml To "commodity"
    Send ComUpdateChildContent To hoXml "active" "true"
    Send ComUpdateChildContent To hoXml "name" "Microsoft Services"
    Send ComUpdateChildContent To hoXml "category" ""
    Send ComUpdateChildContentInt To hoXml "custom-fields|gl-account" 0010

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComGetXmlSb Of hoXml vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "POST" 'https://domain.com/commodities?fields=["id","category","name","active",{"parent":["id","name","category",{"custom_fields":{}}]},{"custom_fields":{}}]' vSbRequestBody "utf-8" "application/xml" False False To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<commodity>
    <active>true</active>
    <name>Microsoft Services</name>
    <category></category>
    <custom-fields>
        <gl-account>0010</gl-account>
    </custom-fields>
</commodity>'
https://domain.com/commodities?fields=["id","category","name","active",{"parent":["id","name","category",{"custom_fields":{}}]},{"custom_fields":{}}]

Postman Collection Item JSON

{
  "name": "Create Commodity",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<commodity>\n    <active>true</active>\n    <name>Microsoft Services</name>\n    <category></category>\n    <custom-fields>\n        <gl-account>0010</gl-account>\n    </custom-fields>\n</commodity>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/commodities?fields=[\"id\",\"category\",\"name\",\"active\",{\"parent\":[\"id\",\"name\",\"category\",{\"custom_fields\":{}}]},{\"custom_fields\":{}}]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "commodities"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\",\"category\",\"name\",\"active\",{\"parent\":[\"id\",\"name\",\"category\",{\"custom_fields\":{}}]},{\"custom_fields\":{}}]"
        }
      ]
    }
  },
  "response": [
  ]
}