0

I'm fairly new to coding and am having issues loading data from the Zomato API with angulars $http. I keep getting invalid API key popping up as an error in my console even though im using the API key generated by Zomato.

Here is a snippet of my code: http://jsfiddle.net/3j1c816v/1/

$http({
    method: 'GET',
    url: 'https://developers.zomato.com/api/v2.1/search?',
    params: {
        user_id: '', // API key
        entity_type: 'city', 
        q: 'food',
    }

Please let me know if i'm doing anything wrong or any helpful resources i can use to fix my issue!

Thank you

kgandroid
  • 5,459
  • 5
  • 37
  • 68

1 Answers1

1

user_key is not a GET parameter but a header parameter.

You should try this:

$http({
    method: 'GET',
    url: 'https://developers.zomato.com/api/v2.1/search?',
    headers: {'user_key' : 'api_key_goes_here'},
    params: {
        entity_type: 'city', 
        q: 'food',
    }
});
Henrique B.
  • 440
  • 3
  • 9
  • thanks i'm pretty sure you're right, however chrome is sending an OPTIONS request and Zomato's api doesn't respond to OPTIONS requests so its breaking :( might switch to different api – mnikolic10 Nov 18 '15 at 23:13
  • That's probably related to CORS, not allowing localhost to consume their API. – Henrique B. Nov 19 '15 at 11:40