Trying to pass a string array of ids into the HTTP Body

Ok…let me see if I can explain what I’m trying to do. I’m new at generating tests against API/Web Services. I am trying to take a String array of ids and use them in a HTTP Body as a way to delete records from a database.

The HTTP Body is:
[
“${idValue1}”,
“${idValue2}”,
“${idValue3}”,
“${idValue4}”,
“${idValue5}”,
]

The lines of code are:
response = WS.sendRequest(findTestObject(‘EntityAPI/data-objects/DELETE Entity By Ids’, [(‘host’) : GlobalVariable.host, (‘idValues’) : GlobalVariable.entId]))
GlobalVariable.entId = WS.getElementPropertyValue(response, ‘data[0].id’)

I am trying understand how to take my String Array of ids and pass them into what I think is supposed to be (‘idValues’). I think the person that left this code for me also wanted me to get the status code to verify the delete occurred and to verify that the response contains an id.

If someone can help, I’d greatly appreciated. Let me know if further information is needed.

Thanks in advance

Welcome Suzanne to the group.

Please add all the idValues from 1 to 5 into Global Variable in actual request

“${idValue1}”,
“${idValue2}”,
“${idValue3}”,
“${idValue4}”,
“${idValue5}”

for this add in test case to verify the response code as WS.verifyResponseStatusCode(response, 200) in script or add it manually

to verify that the response contains an id
For this you need to add below code

def slurper = new groovy.json.JsonSlurper()

def output = slurper.parseText(response.getResponseBodyContent())
println(output)

Let me know if all works for you

Thanks for the response. I checked the API and it does have the five variables already assigned. I think I’m understanding you as saying that I also need to add them as Global Variables? The one thing I definitely need to know is how to pass the list of ids into the code to have the API call delete all records in this one call. I was told that if I don’t send all five ids then the call will fail. The code they provided above is what the person thought I had to do to get this to work, but they were not sure and never completed it.

If I understand your question correctly, all you need to do would be something like this:

def idValue1 = 'foo1'
def idValue2 = 'foo2'
def idValue3 = 'foo3'
def idValue4 = 'foo4'
def idValue5 = 'foo5'
def myStringArray = "['${idValue1}','${idValue2}','${idValue3}','${idValue4}','${idValue5}']"

def response = WS.sendRequest(findTestObject(‘EntityAPI/data-objects/DELETE Entity By Ids’, 
    [(‘host’) : GlobalVariable.host, (‘idValues’) : myStringArray ]))
//                                                  ^^^^^^^^^^^^^

Well, I gave it a shot and it does not delete the records. Any other thoughts? I’m running out of them. Thanks.

def idValue1 = 'foo1'
def idValue2 = 'foo2'
def idValue3 = 'foo3'
def idValue4 = 'foo4'
def idValue5 = 'foo5'
def myStringArray = """[
"${idValue1}",
"${idValue2}",
"${idValue3}",
"${idValue4}",
"${idValue5}"
]"""

def response = WS.sendRequest(findTestObject(‘EntityAPI/data-objects/DELETE Entity By Ids’, 
    [(‘host’) : GlobalVariable.host, (‘idValues’) : myStringArray ]))
//                                                  ^^^^^^^^^^^^^
1 Like

Thanks for the help. I wasn’t able to get it to work with using the array. I was however able to get it to work by passing in each variable individually. I used ‘idValue1’ : idValue1, ‘idValue2’ : idValue2 and so on. I’ll try it again at a later date. Thanks again.