Chilkat Online Tools

DataFlex / Coupa Postman Collection - OAuth - Master / Update PO Line Account Details - COA Name and Segment Values

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"?>
    // <order-header>
    //     <type>ExternalOrderHeader</type>
    //     <po-number>PO-957645-14</po-number>
    //     <order-lines type="array">
    //         <order-line>
    //             <description>Testing Kit 2</description>
    //             <line-num>3</line-num>
    //             <price type="decimal">100.00</price>
    //             <quantity type="decimal">1.0</quantity>
    //             <type>OrderQuantityLine</type>
    //             <account-allocations type="array">
    //                 <account-allocation>
    //                     <amount type="decimal">10.00</amount>
    //                     <pct type="decimal">10.0</pct>
    //                     <account>
    //                         <code>SF-IT-Assets</code>
    //                         <account-type>
    //                             <name>Ace Corporate</name>
    //                         </account-type>
    //                     </account>
    //                 </account-allocation>
    //                 <account-allocation>
    //                     <amount type="decimal">90.00</amount>
    //                     <pct type="decimal">90.0</pct>
    //                     <account>
    //                         <code>SF-Sales-Assets</code>
    //                         <account-type>
    //                             <name>Ace Corporate</name>
    //                         </account-type>
    //                     </account>
    //                 </account-allocation>
    //             </account-allocations>
    //             <currency>
    //                 <code>USD</code>
    //             </currency>
    //             <uom>
    //                 <code>EA</code>
    //             </uom>
    //         </order-line>
    //     </order-lines>
    // </order-header>
    // 

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Set ComTag Of hoXml To "order-header"
    Send ComUpdateChildContent To hoXml "type" "ExternalOrderHeader"
    Send ComUpdateChildContent To hoXml "po-number" "PO-957645-14"
    Get ComUpdateAttrAt Of hoXml "order-lines" True "type" "array" To iSuccess
    Send ComUpdateChildContent To hoXml "order-lines|order-line|description" "Testing Kit 2"
    Send ComUpdateChildContentInt To hoXml "order-lines|order-line|line-num" 3
    Get ComUpdateAttrAt Of hoXml "order-lines|order-line|price" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "order-lines|order-line|price" "100.00"
    Get ComUpdateAttrAt Of hoXml "order-lines|order-line|quantity" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "order-lines|order-line|quantity" "1.0"
    Send ComUpdateChildContent To hoXml "order-lines|order-line|type" "OrderQuantityLine"
    Get ComUpdateAttrAt Of hoXml "order-lines|order-line|account-allocations" True "type" "array" To iSuccess
    Get ComUpdateAttrAt Of hoXml "order-lines|order-line|account-allocations|account-allocation|amount" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation|amount" "10.00"
    Get ComUpdateAttrAt Of hoXml "order-lines|order-line|account-allocations|account-allocation|pct" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation|pct" "10.0"
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation|account|code" "SF-IT-Assets"
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation|account|account-type|name" "Ace Corporate"
    Get ComUpdateAttrAt Of hoXml "order-lines|order-line|account-allocations|account-allocation[1]|amount" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation[1]|amount" "90.00"
    Get ComUpdateAttrAt Of hoXml "order-lines|order-line|account-allocations|account-allocation[1]|pct" True "type" "decimal" To iSuccess
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation[1]|pct" "90.0"
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation[1]|account|code" "SF-Sales-Assets"
    Send ComUpdateChildContent To hoXml "order-lines|order-line|account-allocations|account-allocation[1]|account|account-type|name" "Ace Corporate"
    Send ComUpdateChildContent To hoXml "order-lines|order-line|currency|code" "USD"
    Send ComUpdateChildContent To hoXml "order-lines|order-line|uom|code" "EA"

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"
    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    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 "PUT" 'https://domain.com/purchase_orders/:id?fields=["id"]' 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 PUT
	-H "Authorization: Bearer <access_token>"
	-H "Accept: application/json"
	-d '<?xml version="1.0" encoding="UTF-8"?>
<order-header>
    <type>ExternalOrderHeader</type>
    <po-number>PO-957645-14</po-number>
    <order-lines type="array">
        <order-line>
            <description>Testing Kit 2</description>
            <line-num>3</line-num>
            <price type="decimal">100.00</price>
            <quantity type="decimal">1.0</quantity>
            <type>OrderQuantityLine</type>
            <account-allocations type="array">
                <account-allocation>
                    <amount type="decimal">10.00</amount>
                    <pct type="decimal">10.0</pct>
                    <account>
                        <code>SF-IT-Assets</code>
                        <account-type>
                            <name>Ace Corporate</name>
                        </account-type>
                    </account>
                </account-allocation>
                <account-allocation>
                    <amount type="decimal">90.00</amount>
                    <pct type="decimal">90.0</pct>
                    <account>
                        <code>SF-Sales-Assets</code>
                        <account-type>
                            <name>Ace Corporate</name>
                        </account-type>
                    </account>
                </account-allocation>
            </account-allocations>
            <currency>
                <code>USD</code>
            </currency>
            <uom>
                <code>EA</code>
            </uom>
        </order-line>
    </order-lines>
</order-header>'
https://domain.com/purchase_orders/:id?fields=["id"]

Postman Collection Item JSON

{
  "name": "Update PO Line Account Details - COA Name and Segment Values",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Accept",
        "type": "text",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<order-header>\n    <type>ExternalOrderHeader</type>\n    <po-number>PO-957645-14</po-number>\n    <order-lines type=\"array\">\n        <order-line>\n            <description>Testing Kit 2</description>\n            <line-num>3</line-num>\n            <price type=\"decimal\">100.00</price>\n            <quantity type=\"decimal\">1.0</quantity>\n            <type>OrderQuantityLine</type>\n            <account-allocations type=\"array\">\n                <account-allocation>\n                    <amount type=\"decimal\">10.00</amount>\n                    <pct type=\"decimal\">10.0</pct>\n                    <account>\n                        <code>SF-IT-Assets</code>\n                        <account-type>\n                            <name>Ace Corporate</name>\n                        </account-type>\n                    </account>\n                </account-allocation>\n                <account-allocation>\n                    <amount type=\"decimal\">90.00</amount>\n                    <pct type=\"decimal\">90.0</pct>\n                    <account>\n                        <code>SF-Sales-Assets</code>\n                        <account-type>\n                            <name>Ace Corporate</name>\n                        </account-type>\n                    </account>\n                </account-allocation>\n            </account-allocations>\n            <currency>\n                <code>USD</code>\n            </currency>\n            <uom>\n                <code>EA</code>\n            </uom>\n        </order-line>\n    </order-lines>\n</order-header>"
    },
    "url": {
      "raw": "{{URL}}/purchase_orders/:id?fields=[\"id\"]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "purchase_orders",
        ":id"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\"]"
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "3238"
        }
      ]
    }
  },
  "response": [
  ]
}