Chilkat Online Tools

Node.js / Coupa Postman Collection - OAuth - Master / Create FxRates

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var success;

    // 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"?>
    // <exchange-rate>
    //     <rate type="decimal">0.801539004</rate>
    //     <rate-date type="dateTime">2021-11-22</rate-date>
    //     <from-currency>
    //         <code>USD</code>
    //     </from-currency>
    //     <to-currency>
    //         <code>EUR</code>
    //     </to-currency>
    // </exchange-rate>
    // 

    var xml = new chilkat.Xml();
    xml.Tag = "exchange-rate";
    xml.UpdateAttrAt("rate",true,"type","decimal");
    xml.UpdateChildContent("rate","0.801539004");
    xml.UpdateAttrAt("rate-date",true,"type","dateTime");
    xml.UpdateChildContent("rate-date","2021-11-22");
    xml.UpdateChildContent("from-currency|code","USD");
    xml.UpdateChildContent("to-currency|code","EUR");

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

    var sbRequestBody = new chilkat.StringBuilder();
    xml.GetXmlSb(sbRequestBody);

    // resp: HttpResponse
    var resp = http.PTextSb("POST","[\"code\",\"decimals\"]}]",sbRequestBody,"utf-8","application/xml",false,false);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<exchange-rate>
    <rate type="decimal">0.801539004</rate>
    <rate-date type="dateTime">2021-11-22</rate-date>
    <from-currency>
        <code>USD</code>
    </from-currency>
    <to-currency>
        <code>EUR</code>
    </to-currency>
</exchange-rate>'
https://domain.com/exchange_rates?fields=["id","rate","rate_date",{"from_currency": ["code","decimals"]},{"to_currency": ["code","decimals"]}]

Postman Collection Item JSON

{
  "name": "Create FxRates",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<exchange-rate>\n    <rate type=\"decimal\">0.801539004</rate>\n    <rate-date type=\"dateTime\">2021-11-22</rate-date>\n    <from-currency>\n        <code>USD</code>\n    </from-currency>\n    <to-currency>\n        <code>EUR</code>\n    </to-currency>\n</exchange-rate>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/exchange_rates?fields=[\"id\",\"rate\",\"rate_date\",{\"from_currency\": [\"code\",\"decimals\"]},{\"to_currency\": [\"code\",\"decimals\"]}]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "exchange_rates"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\",\"rate\",\"rate_date\",{\"from_currency\": [\"code\",\"decimals\"]},{\"to_currency\": [\"code\",\"decimals\"]}]"
        }
      ]
    }
  },
  "response": [
  ]
}