cancel
Showing results for 
Search instead for 
Did you mean: 

How to filter out some data while calling api

dipsthorat
New Contributor

How to filter out some data while calling api

Hi 

 

I have one API (1st API)where negative values are coming while calling API , but for further comparison of 1 st API with 2 nd API I dont want negative values while comparing.So how could we filter-out negative data in 1st API while calling itself.

(1st API) Example

[{
"id": -1,
"extendedUicCode": "8400706",

},
{
"id": -1,
"extendedUicCode": "8604704"

},
{
"id": 3
"extendedUicCode": "8015345",

},
{
"id": 2,
"extendedUicCode": "8015343"
}]

2 REPLIES 2
nmrao
Community Hero

Re: How to filter out some data while calling api

Events can be used in this case.

Implement script for beforeSubmit of SubmitListener. Access the request and remove the unwanted and reassign the request with changed request.


Regards,
Rao.
nmrao
Community Hero

Re: How to filter out some data while calling api

Here is the example script that should do what you are looking for.

Place the same for SubmitListener.beforeStep

 

 

import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def temp = context.getProperty('wsdlRequest')
def isSendNegativeValues = context.expand('${#TestCase#SEND_NEGATIVE_VALUE}') ?: 'false'
if ('false' == isSendNegativeValues && temp && (context.getProperty('wsdlRequest').parent instanceof RestTestRequestStep)) {
	def request = context.wsdlRequest.requestContent
	def json = new JsonSlurper().parseText(request)
	def newRequest = JsonOutput.toJson(json.findAll {it.id > 0})
	if (newRequest && request != newRequest) {
		context.wsdlRequest.requestContent = newRequest
	}
}

 

 

However, what do you like to do if you want to send ids with negative values ever? It is not mentioned.

 

You can define test case level custom property SEND_NEGATIVE_VALUE with value true, so that the request is not filter any data. By default, the above script filters with ids of negative values.



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors