Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Xml
oleobject loo_SbRequestBody
oleobject loo_Resp
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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>
//
loo_Xml = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
loo_Xml.Tag = "exchange-rate"
loo_Xml.UpdateAttrAt("rate",1,"type","decimal")
loo_Xml.UpdateChildContent("rate","0.801539004")
loo_Xml.UpdateAttrAt("rate-date",1,"type","dateTime")
loo_Xml.UpdateChildContent("rate-date","2021-11-22")
loo_Xml.UpdateChildContent("from-currency|code","USD")
loo_Xml.UpdateChildContent("to-currency|code","EUR")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Xml.GetXmlSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("POST","[~"code~",~"decimals~"]}]",loo_SbRequestBody,"utf-8","application/xml",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Xml
destroy loo_SbRequestBody
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_Xml
destroy loo_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": [
]
}