How to get Zomato restaurant ID using restaurant link?

12,567

Solution 1

It's a two-step process:

  1. Find out restaurant's city id, in your case, Mumbai's city id through the /cities API. It's a simple query search.
  2. Use the city id from the above API call in the /search API, like, https://developers.zomato.com/api/v2.1/search?entity_type=city&entity_id=3&q=fantasy%20the%20cake%20shop%20kalyan

This would give all the basic information about a restaurant.

Solution 2

View the page's source and search for window.RES_ID

Solution 3

I had the same issue as you described. This Zomato's API approach is at least odd. It's almost immposible to GET any information about restaurant if you don't know res_id in advance and that's not possible to parse since Zomato will deny access.

This worked for me:

  1. Obtain user-key from Zomato API Credentials (https://developers.zomato.com/api)
  2. Search restaurant url via API (https://developers.zomato.com/api/v2.1/search?entity_id=84&entity_type=city&q=RESTAURANT_URL&category=7%2C9). The more specific you will be, the better results you'll get (This url is specified by city to Prague (ID = 84) and categories Daily menus (ID = 7) and Lunch (ID = 9). If there is possibility do specify city, category or cuisine, it helps, but should't be necessary. Don't forget to define GET method in headers.
  3. Loop or filter through json results and search for the wanted url. You might need to use method valueOf() to search for the same url. Be careful, you might need to add "?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1" at the end of your wanted url so it has the same format. Check that through Zomato API Documentation page.
for (i in body.restaurants) {
    var url_wanted = restaurant_url + '?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1'
    var url_in_json = body.restaurants[i].restaurant.url;
    if (url_wanted.valueOf() == url_in_json.valueOf()) {
        var restaurant_id = body.restaurants[i].restaurant.id;
    }
    console.log('Voala! We have res_id:' + restaurant_id);
}
  1. There you have it. It could be easier though.

Hope it helps!

Share:
12,567

Related videos on Youtube

Saeed Jassani
Author by

Saeed Jassani

Updated on June 13, 2022

Comments

Related