Forum Discussion

RealNetworks's avatar
RealNetworks
Occasional Contributor
11 years ago

How to assign a value to a variable in the Request JSON body

I have come to a situation where I need to assign a unique value to an email 'field' REST Request JSON body. I am supposing I will need to write a script to do so but how?

Here's how my json body looks like:
{
"first_name": "testLoadFirstName",
"last_name": "testLoadLastName",
"username": "testloaduser6@merc.com",
"email": "testloaduser6@merc.com",
"password": "WnBaUEFlVk82VktnU2k2QG1lcmN1cnliZXRhLmNvbQ==",
"tos_agree": "true",
"device_id": "loadDeviceId1",
"device_user_agent": "loadTestUserAgent1",
"device_name": "loadTestDeviceName"
}

The value for the email can be something like this:

java.util.UUID.randomUUID() + '@merc.com'


Any help will be highly appreciated. Please let me know if you need any further info. Thanks in advance!

2 Replies

  • RealNetworks's avatar
    RealNetworks
    Occasional Contributor
    Never mind. I found a solution. It could be a potential SoapUI bug that it was not showing the request JSON body from the correct request. It was always picking the GET request although I had explicitly selected the POST request from the drop-down. After I deleted the GET request, it started showing the JSON body when added to a TestCase. Then, I could simply use the Groovy Script to generate the unique email address every time.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Thanks for the information. I'm glad to hear you solved your issues. We'll try to reproduce this to see whether or not it's a bug, and if it is we'll log it in our bug tracking system.

    Let us know if you need assistance in the future.

    Regards,

    Arian
    SmartBear Sweden