Forum Discussion

liki7411's avatar
Occasional Contributor
3 years ago

Trim the node value

I am using  a POST method in ReadyAPI  the response is as follows,   <target_URL>: "http:/<servername>:port/k?key=abcdfee= <httpmethod>GET</httpmethod> <targetpayload null="true"/> <isKBANeeded...
  • ChrisAdams's avatar
    3 years ago



    What you're asking for is achievable.


    Firstly, how to extract the key.  Below is an example groovy script to tease out that value....

    def responseString = '<target_URL>: "http:/<servername>:port/k?key=abcdfee=' +
    	'<httpmethod>GET</httpmethod>' +
    	'<targetpayload null="true"/>' +
    def keyString = "key=";;
    def indexOfKey = responseString.indexOf(keyString);
    def indexEndOfKey =  responseString.indexOf("=", indexOfKey + keyString.length());"Key Start " + indexOfKey + ".  Key end " + indexEndOfKey);
    def key = responseString.substring(indexOfKey, indexEndOfKey);;
    key = key.replace(keyString, "");;
    return key;


    So, after the first call that returns the 'key', create a Groovy Script step called 'GetKey' and use the above example to read the response from the first call.  You will obviously have to tailor this to read from your first call.


    If your second API call is in the same test, then don't bother with property transfers etc.


    Simply pull in the value from the Groovy script and squirt it into the hear.  Go your second API call and click on the Headers tab.  Add Key ( or whatever it needs to be) and in value, you call the Groovy script...


    That dollar notation is great.  The above screenshot says 'call step GetKey and get the result value'.  When you run your test, ReadyAPI will substiture this for the actual value.

    If something isn't quite right, use the Raw tab to see the payload (with substituted variables) that ReadyAPI actually sent.



  • liki7411's avatar
    3 years ago

    Thanks a lot !!