0

I am able to pass the JSON data as Query Parameters in which I am passing particular kit_config_id in the form of HasMap. Now I want the API to return the data related to only specified kit_config_id but its giving me all records.

What wrong I am doing here?

// Request object using RestAssured
RequestSpecification httpRequest = RestAssured.given();

HashMap<String, String> params = new HashMap<String, String>();
params.put("kit_config_id", "60db53ec7a334172b005b692");

Response response = httpRequest.given().baseUri("https://qa-api-test.com").param("query", params).when().get("/imageProps");

Complete Url of GET call is : https://qa-api-tests.com/imageProps?params={"query": {"kit_config_id": "60db53ec7a334172b005b692"}}

3
  • What makes you sure you’re ‘passing JSON data as query parameters’? Have you tried calling it from postman (or similar) to check how you’re supposed to serialising the JSON? Are you sure you need it to be JSON, not just use the queryParam method on RequestSpecification? Commented Jun 29, 2021 at 18:29
  • I have tried below way also but again its giving me all records : HashMap<String, Object> params = new HashMap<String, Object>(); params.put("kit_config_id", "60db0d5d7a334172b005b665"); HashMap<String, Object> query = new HashMap<String, Object>(); query.put("query", params); // Add Base URI by using RestAssured String url = RestAssured.baseURI = "qa-api-test.com"; // Request object using RestAssured RequestSpecification httpRequest = RestAssured.given().queryParams( query); Response response = httpRequest.request(Method.GET); Commented Jun 29, 2021 at 18:46
  • I’m not sure that answers any of my questions. What are you expecting your query string to look like? Commented Jun 29, 2021 at 19:13

1 Answer 1

1

If you want query like this

/imageProps?params={"query":{"kit_config_id":"60db0d5d7a334172b005b665"}}

Using this:

HashMap<String, Object> kit_config = new HashMap<>();
kit_config.put("kit_config_id", "60db0d5d7a334172b005b665");
HashMap<String, Object> query = new HashMap<>();
query.put("query", kit_config);

RestAssured.given().log().all().baseUri("your-url")
        .queryParams("params", query)
        .when().get("/imageProps");

If you want query like this

/imageProps?kit_config_id=60db53ec7a334172b005b692

Just need:

HashMap<String, Object> kit_config = new HashMap<>();
kit_config.put("kit_config_id", "60db0d5d7a334172b005b665");

RestAssured.given().log().all().baseUri("https://postman-echo.com")
        .queryParams(kit_config)
        .when().get("/imageProps");
Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot, it worked like a charm for me...actually I was doing a silly mistake earlier ...was not adding "params"

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.