Chilkat Online Tools

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

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkXmlW xml;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    // 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>
    // 

    xml = CkXmlW_Create();
    CkXmlW_putTag(xml,L"order-header");
    CkXmlW_UpdateChildContent(xml,L"type",L"ExternalOrderHeader");
    CkXmlW_UpdateChildContent(xml,L"po-number",L"PO-957645-14");
    CkXmlW_UpdateAttrAt(xml,L"order-lines",TRUE,L"type",L"array");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|description",L"Testing Kit 2");
    CkXmlW_UpdateChildContentInt(xml,L"order-lines|order-line|line-num",3);
    CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|price",TRUE,L"type",L"decimal");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|price",L"100.00");
    CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|quantity",TRUE,L"type",L"decimal");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|quantity",L"1.0");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|type",L"OrderQuantityLine");
    CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|account-allocations",TRUE,L"type",L"array");
    CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|account-allocations|account-allocation|amount",TRUE,L"type",L"decimal");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation|amount",L"10.00");
    CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|account-allocations|account-allocation|pct",TRUE,L"type",L"decimal");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation|pct",L"10.0");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation|account|code",L"SF-IT-Assets");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation|account|account-type|name",L"Ace Corporate");
    CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|account-allocations|account-allocation[1]|amount",TRUE,L"type",L"decimal");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation[1]|amount",L"90.00");
    CkXmlW_UpdateAttrAt(xml,L"order-lines|order-line|account-allocations|account-allocation[1]|pct",TRUE,L"type",L"decimal");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation[1]|pct",L"90.0");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation[1]|account|code",L"SF-Sales-Assets");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|account-allocations|account-allocation[1]|account|account-type|name",L"Ace Corporate");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|currency|code",L"USD");
    CkXmlW_UpdateChildContent(xml,L"order-lines|order-line|uom|code",L"EA");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");
    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    sbRequestBody = CkStringBuilderW_Create();
    CkXmlW_GetXmlSb(xml,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://domain.com/purchase_orders/:id?fields=[\"id\"]",sbRequestBody,L"utf-8",L"application/xml",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkXmlW_Dispose(xml);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkXmlW_Dispose(xml);
    CkStringBuilderW_Dispose(sbRequestBody);

    }

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": [
  ]
}