Ask a Question

Using parameters in JSON Body in REST HTTP POST method

jzyling
Occasional Contributor

Using parameters in JSON Body in REST HTTP POST method

Hi,

I am trying to create a REST HTTP Request for a POST Method, using JSON data in the body. I am trying to use parameters instead of values in the body. For example:

POST Body:
{
"accountId":${accountID},
"userId":${userID}
}

I named a parameter as accountID with a long-type value like 1380000 of PLAIN style. I also named a parameter as userID with a long-type value like 250000000 of PLAIN style.

But after I submitted the POST request, the data in Raw became
{
"accountId":,
"userId":
}

I am wondering why those values were not taken? How to make it JSON style instead of PLAIN style?

Thanks a lot in advance!
5 REPLIES 5
lostiniceland
New Contributor

Re: Using parameters in JSON Body in REST HTTP POST method

I've currently having the same propblem. After reading the documentation over and over again and trying all kinds of Property-Expansions the value is always empty.

 

Using SoapUI 5.2.0

rupert_anderson
Valued Contributor

Re: Using parameters in JSON Body in REST HTTP POST method

Hi,

 

I think what was not clear from the orignal post is exactly what scope of parameters he/you are intending to use?

 

What I mean by that is, the syntax for referencing the properties in the original post used the default scope e.g. ${accountID}, this is correct if the properties were added to the TestCase context variable as properties, or failing that, if the properties were added as Global or System properties (see http://www.soapui.org/scripting---properties/property-expansion.html) - does this make sense?

 

So where or on what type of object have you set the properties that you need to reference e.g. TestCase, Project, context level etc?

 

Cheers,

Rupert

Author of SoapUI Cookbook
lostiniceland
New Contributor

Re: Using parameters in JSON Body in REST HTTP POST method

Thanks for the reply, I've already read the mentioned link. Let me clarify what I intended to do

 

Since TestSuites use the Requests I added to the project I wanted to use a method-level parameter for the resource-request. My hope was that I can set some default options which I can also select with an expression. This is what the screenshot shows.

 

SoapUI_5.2.0_Method-Parameter.jpg

Since this didnt work I tried using a actual value in the parameter-value without success.

 

So I skipped the idea of a "generic" request and wanted to access the TestCase property which is defined as id and gets its value via a property-transfer

 

SoapUI_5.2.0-TestCase-Properties.jpg

 

According to the documentation I tried a property-expansion in various ways:

"ticketId" : "${#TestCase#id}"

"ticketId" : "${#Properties#id}" // mentioned in some forum

"ticketId" : "${=testRunner.testCase.getProperty('id')}"

"ticketId" : "${=testRunner.testCase.getPropertyValue('id')}"

// just tried the following since nothing else seemed to work
"ticketId" : "${=testRunner.testCase.testSuite.getProperty('id')}"

"ticketId" : "${=testRunner.testCase.testSuite.getPropertyValue('id')}"

 

Just to be clear: the property in the testcase is successfully set by the property-transfer, so there is a valid value at runtime.

 

 

 

lostiniceland
New Contributor

Re: Using parameters in JSON Body in REST HTTP POST method

Partial solution, after more try-and-error

 

 

 

${Properties#id}

works, where Properties is the Step-name. Carefull about the #, in order to reference a step, no leading # has to be used.

 

I do like SOAP-UIs capabilities, but the usability is kind of...difficult...how about a fresh JavaFX-Frontend 😉

 

rupert_anderson
Valued Contributor

Re: Using parameters in JSON Body in REST HTTP POST method

Hi,

 

Ok, glad you're getting somewhere.

 

Have been a bit busy, but was going to also suggest that you try just adding a simple context based property and then referencing that e.g.

 

In a Groovy TestStep preceeding your Resquest TestStep, add a context property like

 

context["testProp"]="hello1"

 

Then in the Request TestStep, resoolve this with ${testProp} - this should definately work.

 

Then other types of property references e.g. from wider scopes like TestCase, TestSuite, Project etc all should work fine, Just a question of getting the scope syntax right. BTW the pro version of SoapUI has a nice little feauture for forming the correct reference for you in a point and click way, not that I have SoapUI pro anymore! The open-source version takes a bit more practice.

 

The property expansion / scripting part of SoapUI is one of its best features in my opinion, but the syntax can take a little practice though as you say! 🙂

 

Glad you got something working anyway,

 

Cheers,

Rupert

Author of SoapUI Cookbook
cancel
Showing results for 
Search instead for 
Did you mean: