Insert N posts with the API error 500

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.forEach(function(res) {

        const payload = { posts: [{         
            "title": "title",
            "tags":  ["tag"],
            "authors": [""],
            "meta_description": "meta_description",
            "meta_title": "title",
            }] };

  , payload, { headers })
                .then(response => console.log(response))
                .catch(error => console.error(error));


Hi @Kevin , sorry if I tag you, I still have this problem, do you have any suggestions?


  errors: [
      message: 'Database error, cannot save post.',
      context: 'Unable to update nested relation. [object Object]',
      type: 'BookshelfRelationsError',
      details: null,
      property: null,
      help: null,
      code: 'UPDATE_RELATION',
      id: 'e5a3a9b0-723a-11eb-860f-a150bebc1eb6'

If anyone is interested, I solved the problem by delaying each entry by one second.