Service Virtualization

Expand all | Collapse all

REST call with dynamic URL

Jump to Best Answer
  • 1.  REST call with dynamic URL

    Posted 06-12-2016 12:21 PM


    For a test that I'm developing uing DevTest 91: I have a situation where the first thing I do is that I create something in SUT (I send in key1) and that will give me a response(salesID). Based on that response I later (not just after) need  to make another  REST call bases on the return value. I have inserted a JSR-223 script that builds a hash  = saleryMap[key1,salesID].

    I would then like to make a REST call like:

    api/v1/salesopportunity/{{salaryMap[1004]}}/offer that I hoped would work. Instead I get "ERROR - Could not evaluate expression '=salaryMap[1004]'"

    I'm not at all used to working in workstation (nor DevTest), is there perhaps something I need to do to "export" my hasmap from the JSR-223 step so all consequent steps is aware of the map??


    Kind regards,


  • 2.  Re: REST call with dynamic URL

    Posted 06-12-2016 12:29 PM

    Your map is deleted when the JSR-223 step completes. One way to save a map is to use a SharedModelMap.

    DevTest 8.0 - Scripting Guide - V1.1.pdf contains an explanation.

  • 3.  Re: REST call with dynamic URL

    Posted 06-13-2016 04:52 AM

    Based on your explanation my take is you only have a single key that you want to substitute dynamically in the REST URL. If that's correct then you can leverage testExec for this purpose ( testExec - specifies the current test execution environment).


    In JSR-223 step you can set the key like this:


    Later in any subsequent steps you can access the value of salarymapkey in REST URL like this



    The value of property salarymapkey won't change until the next cycle of test execution till you fetch new salesID.


    Assuming there are multiple key values in that case you should look at leveraging SharedModelMap as Rick explained earlier.


    Populate the map in JSR-223 step as follows (sample code snippet)

    import com.itko.lisa.vse.SharedModelMap;


    if (!SharedModelMap.containsKey(salarymapkey)) {



    REST URL should be constructed like this


  • 4.  Re: REST call with dynamic URL
    Best Answer

    Posted 06-13-2016 08:26 AM

    You need to save the hash pointer into the DT variable table.  (setStateObject or the shareable api),

    and then either use that in the variable substitution syntax.. OR, just use the groovy syntax, to construct the string on the fly.

    hash = testexec.getStateObject(hashkename)

    url  = "api/v1/salesopportunity/" + hash.get(transkey) + "/offer"

  • 5.  Re: REST call with dynamic URL

    Posted 06-14-2016 02:29 PM


    I used this approach, and was happy with it!