1

I'm triggering the Zomato api for the collections request, however, I keep getting the headers as if they were text/html. Postman returns them as JSON, which is what I need. All other Zomato apis I've tested so far are returning JSON but collections and not sure why. That's what I have on my attempts to force the JSON as the type for the response.

@Test
public void testGetCousinesApiReturnsItemsInAscendingAlphabeticalOrder() {

    Map<String, Object> map = new HashMap<>();
    map.put("city_id", 61);

    Response r = given()
            .baseUri(baseUrl)
            .basePath("/cousines")
            .queryParams(map)
            .contentType(ContentType.JSON)
            .accept(ContentType.JSON)
            .contentType("application/json\r\n")
            .header("Accept", "application/json").and()
            .header("Content-Type", "application/json")
            .header("user-key", zomatoKey)
            .log().body(false)
            .get();

    System.out.println(r.getContentType());
}
Francislainy Campos
  • 3,462
  • 4
  • 33
  • 81

1 Answers1

0

I convert response to JsonPath :

 public static JsonPath getJsonPath (Response res) {
        String json = res.asString();
        System.out.println("returned json: " + json);
        return new JsonPath(json);
    }

and then use this JsonPath to get each value of Response:

JsonPath jp = getJsonPath(res);
String type = jp.get("type");
ssharma
  • 935
  • 2
  • 19
  • 43
  • Hi, thanks for your response. Don't think this is possible as res.asString() wouldn't be a valid json to be given as a param to JsonPath, as the response is returning html, which is the issue I'm trying to solve. – Francislainy Campos Feb 22 '20 at 20:41