简体   繁体   中英

Zomato api is not working in Nodejs

I need to get the review of a particular restaurant using Zomato Api in Nodejs.But this api is working in postman .

邮递员回应

But it is not working in Nodejs .

Node.js响应 app.js

var https = require('https');
var request = require('request');
var zomatoUserKey = '****************************';
var postheaders = {
  'Content-Type': 'application/json; charset=utf-8',
  'user-key': zomatoUserKey
};
var optionspost = {
  host: 'developers.zomato.com', // here only the domain name
  path: 'api/v2.1/reviews', // the rest of the url with parameters if needed
  headers: postheaders,
  method: 'POST',
  data: '{"res_id": "zoma.to/r/34343"}'
};
https.request(optionspost, function(error, response, body) {
  console.log('error', error);
  console.log('body', body);
  console.log('response', response);
});

As per the documentation of Zomato API you need to use GET request instead of POST .

var optionspost = {
  host: 'developers.zomato.com', // here only the domain name
  path: '/api/v2.1/reviews', // the rest of the url with parameters if needed
  headers: postheaders,
  method: 'GET',
  // -------^----
  data: '{"res_id": "zoma.to/r/34343"}'
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM