-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.js
37 lines (32 loc) · 849 Bytes
/
fetch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fetch = require('node-fetch');
const { downloadProducts } = require('./download')
const fetchProducts = (page, url, key) => {
fetch(url, {
method: 'POST',
headers: {
'NETOAPI_ACTION': 'GetItem',
'NETOAPI_KEY': `${key}`,
'Accept': 'application/json'
},
body: JSON.stringify({
'Filter': {
'IsActive': ["True", "False"],
"Limit": "100",
"Page": `${page}`,
'OutputSelector': [
'Images'
]
}
})
})
.then(res => res.json())
.then(data => data.Item)
.then(products => {
downloadProducts(products)
if (products.length > 0) {
let nextPage = page + 1;
fetchProducts(nextPage, url, key)
}
}).catch(err => console.log(err));
}
module.exports = { fetchProducts };