Vishwas Srinivas
Vishwas Srinivas

Reputation: 19

ZOMATO - INVALID API Key error in Eclipse but in POSTMAN response is a success

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"
            }
        }
    ]
}

Upvotes: 1

Views: 1276

Answers (3)

Abhishek Bajaj
Abhishek Bajaj

Reputation: 1

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>);                  

Upvotes: 0

Ammar Halbouni
Ammar Halbouni

Reputation: 79

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.

Upvotes: 1

ravindu1024
ravindu1024

Reputation: 1534

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>)

Upvotes: 0

Related Questions