【发布时间】:2020-01-29 02:55:56
【问题描述】:
我正在尝试使用以下代码从 Zapier 中的分页 API 中获取所有记录。
const limitPerPage = 20;
const apiUrl = "https://myurl.com/data";
var lastCursor = null;
var output = null;
const getContent = async function (cursor) {
let actualUrl = apiUrl + `?cursor=${cursor}&limit=${limitPerPage}`;
var apiResults = await fetch(actualUrl)
.then(resp => {
return resp.json;
});
}
const getEntireContentList = async function (cursor) {
const results = await getContent(cursor);
console.log("Retreiving data from API for cursor : " + cursor);
if (results.metadata.cursor !== "") {
return results.concat(await getEntireContentList(results.metadata.cursor));
} else {
return results;
}
};
(async() => {
const entireList = await getEntireContentList();
console.log(entireList);
output = entireList;
callback(null, entireList);
})();
我得到错误
您没有定义output!试试output = {id: 1, hello: await Promise.resolve("world")};
我该如何解决这个问题?
【问题讨论】:
标签: javascript zapier