0

I'm trying to get the data stored in the zomato api and on checking a few urls generated in the site, for example,

<a href="https://developers.zomato.com/api/v2.1/restaurant?res_id=RESID">

https://developers.zomato.com/api/v2.1/restaurant?res_id=RESID,

I'm getting an error message saying:

{"code":403,"status":"Forbidden","message":"Invalid API Key"}

whereas this same url is giving a json format response of data about some restaurant.Also,I have a zomato API key generated.Yet,the problem. Do let me know where I'm wrong so I can correct myself.

Thank you.

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
Ahaan R
  • 1
  • 1
  • 2

4 Answers4

1

Try passing the Zomato api key from the header of http request instead of passing the key in the querystring

rahul
  • 552
  • 6
  • 11
1

If you're trying to fetch the API to get a response data.

pass the API key through the header

axios({
      method: "GET",
      url: "https://developers.zomato.com/api/v2.1/search",
      headers: {
        "user-key": "API_KEY",
        "content-type": "application/json"
      }
    })
      .then(response => {
        console.log(response.data.restaurants[0].restaurant.name);
      })
      .catch(error => {
        console.log(error);
      });
0

In javascript structure the api call this way:

$.ajax({  
url: "https://developers.zomato.com/api/v2.1/restaurant?res_id=RESID",
dataType: 'json',
async: true,
beforeSend: function(xhr){xhr.setRequestHeader('user-key', 
'INSERT_API_KEY_HERE');},  // This inserts the api key into the HTTP header
success: function(response) { console.log(response) } });
R Diaz
  • 22
  • 4
-1
 public Map < String, String > getHeaders() {
    Map < String,
    String > params = new HashMap < String,
    String > ();
    params.put("user-key", "xxx");
    params.put("Accept", "application/json");
    return params;
  }
  • 2
    While a code only answer might help the questioner, the community appreciates the explanation. Could you please provide details on why and how this works? – creyD Jan 23 '21 at 13:40