wmnitin wmnitin - 1 year ago 182
reST (reStructuredText) Question

Ajax call to Zomato API is not working

I am trying to access zomato api.

URL: https://developers.zomato.com/api/v2.1/categories

Headers: 'X-Zomato-API-Key':'myapikeyhere-763demoapi434'

If I use chrome's postman extension or curl then I can access the url & getting 200 status code.

But if I run it through my angular2 app or simple ajax, it is giving error at preflight OPTIONS request, error code is 501. I have tried otherways too, error is same. Need help

Answer Source

Zomato API's can only be accessed from server to server calls, the error message you have reported is a security policy implemented by Chrome to prevent cross site request forgery on the client side.

A way you can get around this is to write a handler on your server end to make handler which the ajax call will use, this handler in-turn makes a request to the Zomato's server to retrieve the data required.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download