Hi All,
I have a usecase where I need to send an HTTP request with an XML or JSON body. In the API Proxy, I would like to add an element (sum of two other elements) and then obtain the modified body.
My XML request is:
<?xml version="1.0" encoding="utf-8"?>
<Add>
<a>10</a>
<b>20</b>
<c>Total</c>
</Add>
My JSON request is:
{
"Add": {
"a": "10",
"b": "20",
"c": "Total"
}
}
JavaScript code for adding two elements a and b:
var a=context.getVariable("request.body.Add.a");
var b=context.getVariable("request.body.Add.b");
//var a=context.getVariable("request.queryparam.a.N");
print("a"+a);
print("b"+b);
var Total = parseInt(a) + parseInt(b);
context.setVariable("request.body.c",Total);
In Trace tool i’m getting 200 as a response but unable to get proper output :
Output from all Transactions:
anull
bnull
Postman response Is :
{
"args": {},
"data": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Add>\n <a>10</a>\n <b>20</b>\n <c>Total</c>\n</Add>\n",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Cache-Control": "no-cache",
"Content-Length": "88",
"Content-Type": "application/xml",
"Host": "httpbin.org",
"Postman-Token": "690d3cd0-de25-44af-9451-8aec1945c2",
"User-Agent": "PostmanRuntime/6.4.1"
},
"json": null,
"origin": "114.79.146.115, 104.154.179.1, 114.79.146.115",
"url": "https://httpbin.org/post"
}
Could someone please help me?
Any Advice what i’m doing wrong here?
Thanks and Regards
Govind Verma