bulkDestroy throws TOO_MANY_OPERATIONS OR A 404 while deleting all records

Hi,

I was trying to delete all records in my sandbox env using this piece of code.
I use the full access token here.

const recordObj=[];
    for await (const record of client.items.listPagedIterator({version:"current"})) {
        recordObj.push({
            type: record.type,
            id: record.id
        })

      }

      const result = await client.items.bulkDestroy({
        items: recordObj
      });

The part of code that retrieves all records gives me all the records from different pages (including my schema migrations) which is exactly what I want but it throws a this error:

    body: {
      data: [
        {
          id: 'a6c24d',
          type: 'api_error',
          attributes: { code: 'TOO_MANY_OPERATIONS', details: {} }
        }
      ]
    }
  },

There are totally 1720 records so I reduced them to maybe a 100 or 50 in batch but this gives me a 404 now. Further reducing it to 5 worked occasionally for some ids, for some it still threw a 404 even though it was existing. Based on what I see, bulkDestroy does not identify records belonging to different pages/models when given at once. Is this expected?

Also the reason I am doing this is because I want a sandbox env without any data where I can test my backup/restore scripts. Is there possibly a better way to do this, like a fork a env without any data?

Hello @persis.jerifa.nelson.david.gift.jebakuma

The issue is: Each bulk request can take at most 200 IDs at once, if you want to do more than that, you’ll need to do it across more requests, so 400 Publications across 2 requests, 1000 publications across 5 requests and so on.

Thanks for the reply. But as I also mentioned, it’s not just the limit of data that is the issue here. Even when I send just 5 or 10 IDs belonging to different pages/models, it throws a 404 error.

@persis.jerifa.nelson.david.gift.jebakuma the 404 occurs when you are trying to delete a non existent record/ a record that has already been deleted.
If you are getting a 404 for an existing record ID email us at support@datocms.com with the request being made as well as the URL of the record that shouldn’t be returning the 404 so we can take a look on our end.