Hi All,
I have a usecase where I have to send an HTTP request with an XML and JSON body. In the API Proxy, I would like to add an element (sum of two elements i.e, a & b) and then obtain the modified body only c as a response by adding the value of a & b.
My XML request by PostMan is:
<?xml version="1.0" encoding="utf-8"?> <Add> <a>40</a> <b>70</b> <c>Total</c> </Add>
My JSON request by PostMan is:
{"Add":{"a":"40","b":"70","c":"Total"}}
JavaScript code for adding two elements a and b and to print only "total as a response":
var a=context.getVariable("request.body.Add.a"); var b=context.getVariable("request.body.Add.b"); var Total = parseInt(a) + parseInt(b); context.setVariable("request.body.Add.c",Total); print(body.Add.c);
Expected Output:(Only addition of 2 nos) i.e,
Total = 110
But My Postman response Is :
{"fault":{"faultstring":"Execution of JavaScript-1 failed with error: Javascript runtime error: \"TypeError: Cannot read property \"Add\" from undefined. (JavaScript-1.js:2)\"","detail":{"errorcode":"steps.javascript.ScriptExecutionFailed"}}}
Could someone please help me?
Any Advice what i'm doing wrong here?
Thanks and Regards
Govind Verma
@Anil Sagar @ Google, @Dino-at-Google,@Brendan, @deboraelkin,@Siddharth Barahalikar,@Priyadarshi Ajitav Jena,@Robert Johnson,@Nisha Mallesh,@Anil Sagar,@sudheendras,@Mukundha Madhavan,@Jeremy Whitlock,@Nagashree B