【发布时间】:2019-03-20 21:39:03
【问题描述】:
我正在使用 Node.js,但在对外部 API 的 GET 请求中执行 GET 请求时遇到问题。我似乎遇到问题的地方是 API 密钥,但我不确定 100%。当我发出请求时,我只返回一个带有 200 状态代码的空 JSON 对象。我有我做错了什么?
const express = require('express');
const router = express.Router();
const promisify = require('util').promisify;
const request = promisify(require('request'));
const apiURL = "https://a.klaviyo.com/api/v2";
router.get('/lists', async(req, res) => {
try {
request.get({
url: 'https://a.klaviyo.com/api/v2/lists',
headers: {
"content-type": "application/json"
},
body: {
"api_key": */omitted for security/*
}
}, ( error, response, body) => {
const data = JSON.parse(body)
res.send(body)
})
} catch (error) {
res.send(error)
}
})
module.exports = router
【问题讨论】:
标签: javascript node.js rest api express