I want to insert N posts using the API in a foreach loop, only the first post is inserted, then I get an error 500, probably due to axios:
Error: Request failed with status code 500
at createError (/home/user/node_modules/axios/lib/core/createError.js:16:15)
at settle (/home/user/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/home/user//node_modules/axios/lib/adapters/http.js:260:11)
at IncomingMessage.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
this is the code I use simplified:
arr=["test1","test2"]
arr.forEach(function(res) {
const payload = { posts: [{
"title": "title",
"tags": ["tag"],
"authors": ["email@domain.it"],
"html":res,
"meta_description": "meta_description",
"meta_title": "title",
}] };
axios.post(urlInsert, payload, { headers })
.then(response => console.log(response))
.catch(error => console.error(error));
})