的API请求我走线槽某些阵列:的Node.js与HTTP请求循环
'邮件','20 05:32' .03.2017,'11 03:44' .07.2017, “ 2' , '0', '2', '0', '4', '3', '46']
为每个阵列我做3嵌套请求 但现在我有我的索引索引有时是错误的问题。我认为我的循环比请求更快。我如何可以采取以下方式:
- 开始for循环指数= 1
- 进行API调用1索引1
- 等待API调用1个响应
- 进行API调用2索引1
- 等待API调用2
- 进行API调用3索引1
等待的响应为API调用的响应3
指数++
进行API调用1指数2 ......
for (var i = 1; i <= (csvData.length-1); i++){
var options = { method: 'GET',
url: 'https://api.pipedrive.com/v1/persons/find',
qs:
{ term: csvData[i][0],
start: '0',
search_by_email: '1',
api_token: '' },
headers:
{ 'postman-token': '',
'cache-control': 'no-cache' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
var user = JSON.parse(body);
console.log("-->User gefunden<--");
console.log("-->User: "+user.data[0].name+"<--");
var options = { method: 'GET',
url: 'https://api.pipedrive.com/v1/deals/find',
qs:
{ term: user.data[0].name,
api_token: '' },
headers:
{ 'postman-token': '',
'cache-control': 'no-cache' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
var deal = JSON.parse(body);
var options = { method: 'PUT',
url: 'https://api.pipedrive.com/v1/deals/'+deal.data[0].id,
qs: { api_token: '' },
headers:
{ 'postman-token': '',
'cache-control': 'no-cache',
'content-type': 'application/json' },
body: { stage_id: csvData[i-1][9]},
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
});
});
});
}
});
首先你有一个语法错误。请先解决。 – Aron