I'm testing API, using Rest assured, programming language is java. Is there any way to get the generated id from a response body and insert it into the endpoint?

I have the following endpoint {baseUrl}/api/product/{id}/deleteActivity

I want clean up after myself, every time when I create a new POST, its generating new id, I want to get that id put it in the endpoint, and delete the created product, so that I don't have to change the id every time manually.

response = when().request("Delete","{baseUrl}/api/product/{id}/deleteActivity");

1 Answer 1


From RestAssured docs, you can do the following:

String json = post(URL_TO_CREATE_ENTITY).asString();
String id = from(json).get("generatedId"); // Or whatever is the name of the attribute with the ID

Then you can make a call with this value:

String urlToDelete = "{baseUrl}/api/product/" + id + "/deleteActivity"
  • Thank you @João Farias Jul 12, 2021 at 10:06
  • If the answer is satisfactory, could you mark it as Accepted, so other people will know it is the correct one? Jul 12, 2021 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.