Chilkat Online Tools

delphiDll / Coupa Postman Collection - OAuth - Master / Create FxRates

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
xml: HCkXml;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;

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

http := CkHttp_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"?>
// <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>
// 

xml := CkXml_Create();
CkXml_putTag(xml,'exchange-rate');
CkXml_UpdateAttrAt(xml,'rate',True,'type','decimal');
CkXml_UpdateChildContent(xml,'rate','0.801539004');
CkXml_UpdateAttrAt(xml,'rate-date',True,'type','dateTime');
CkXml_UpdateChildContent(xml,'rate-date','2021-11-22');
CkXml_UpdateChildContent(xml,'from-currency|code','USD');
CkXml_UpdateChildContent(xml,'to-currency|code','EUR');

// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');

sbRequestBody := CkStringBuilder_Create();
CkXml_GetXmlSb(xml,sbRequestBody);

resp := CkHttp_PTextSb(http,'POST','["code","decimals"]}]',sbRequestBody,'utf-8','application/xml',False,False);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkXml_Dispose(xml);
CkStringBuilder_Dispose(sbRequestBody);

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