In TestRigor, how do you "grab value" in the API response?

136 Views Asked by At

If I'm making a POST call, and the response is 200 ok. How would I grab one of the ID fields listed in the response? The documentation seems to hint that 'and get "JsonPath" and save it as "variableName" ' will do the trick, but no luck.

The goal is to use the ID field that is captured in the response as a param in another PUT call that I intend to make in the next step of the test case.

For example, my test case would look something like this:

//Step 1: Create record_id call api "<API_URL>" with headers "a:a" and "b:b" and body "body" and get "record_id" and save it as "var_record_id"

//Step 2: Update the specific record_id from POST call to a permitted state call api "<API_URL>" with headers "a:a" and "b:b" and body from the string with parameters text starting from next line and ending with [END] { "param": "var_record_id", "state": "permit"

} [END]

1

There are 1 best solutions below

0
Alejandro Mayorga On

This is how i use it: call api post from the string with parameters ${urlApi}/${vehicleInfoUrlPageName}/${requestSessionApiEndPoint} with headers from the string with parameters ${ContentTypeHeader} and body from the string with parameters text starting from next line and ending with [END]

${requestBody}

[END] and get $ and save it as endpointResponseData and get $.sessionId and save it as sessionIdFromResponse get $.success and save it as successFlag and get $.pId and save it as pidFromResponse and get $.data and save it as dataObjectFromResponse and get $.error and save it as errorObjectFromResponse and then check that http code is 200