1

I am executing a GET request of the ZOMATO API the POSTMAN tool returns a successfull response, however when I try with Eclipse it returns the below message : 403 Error Invalid API Key

The API key am using in POSTMAN and Eclipse are the same have double checked.

The eclipse code is as stated below:

public class exampleTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        RestAssured.baseURI = "https://developers.zomato.com";

        Response res = given().
        param("user-key", <api_key>).
        when().
        get("/api/v2.1/categories").
         then().assertThat().statusCode(400).and().contentType(ContentType.JSON).extract().response();

In POSTMAN tool am passing the key in the header rather the URL and response is a success as below:

{
    "categories": [
        {
            "categories": {
                "id": 1,
                "name": "Delivery"
            }
        },
        {
            "categories": {
                "id": 2,
                "name": "Dine-out"
            }
        },
        {
            "categories": {
                "id": 3,
                "name": "Nightlife"
            }
        },
        {
            "categories": {
                "id": 4,
                "name": "Catching-up"
            }
        },
        {
            "categories": {
                "id": 5,
                "name": "Takeaway"
            }
        },
        {
            "categories": {
                "id": 6,
                "name": "Cafes"
            }
        },
        {
            "categories": {
                "id": 7,
                "name": "Daily Menus"
            }
        },
        {
            "categories": {
                "id": 8,
                "name": "Breakfast"
            }
        },
        {
            "categories": {
                "id": 9,
                "name": "Lunch"
            }
        },
        {
            "categories": {
                "id": 10,
                "name": "Dinner"
            }
        },
        {
            "categories": {
                "id": 11,
                "name": "Pubs & Bars"
            }
        },
        {
            "categories": {
                "id": 13,
                "name": "Pocket Friendly Delivery"
            }
        },
        {
            "categories": {
                "id": 14,
                "name": "Clubs & Lounges"
            }
        }
    ]
}
ravindu1024
  • 1,496
  • 1
  • 13
  • 30

3 Answers3

1

I had this error just try this it will work,

instead of using user-key just use apikey.

developers.zomato.com/api/v2.1/categories?apikey=your API key

Good luck.

0

You're passing the api key as a query param in RestAssured. It should be passed as a header param. Like this:

.header("user-key", <api_key>)
ravindu1024
  • 1,496
  • 1
  • 13
  • 30
0

For me, it worked with by using headers instead of header function call.

RequestSpecification requestSpec=RestAssured.given().headers("Content-Type","application/json","user-key",<api-key>);                  
Greedo
  • 3,438
  • 1
  • 13
  • 28