Zomato api在Nodejs中不起作用

时间:2016-07-02 07:35:18

标签: javascript node.js express request zomato-api

我需要在Nodejs中使用Zomato Api查看特定餐厅。但这个api正在 postman 中工作。

postman response

但它不适用于 Nodejs

Nodejs response 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);
});

1 个答案:

答案 0 :(得分:0)

根据documentation of Zomato API,您需要使用GET请求而不是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"}'
};