Destroy and bulkDestroy fail with 404

Both destroy and bulkDestroy are failing with a ApiException: 404 NOT_FOUND (details: {}) without further details.

The setup as per the documentation:

(Using a full access token)

const SiteClient = require('datocms-client').SiteClient;
const client = new SiteClient('supersecrettokenYouSeeNothingHere', { environment: 'development' });

async function main(){
  const records = (await client.items.all(
      {
        filter: {
          type: "bad_block_whose_records_need_to_be_deleted",
        },
      },
      {
        allPages: true,
      }
  )).map(r => r.id);
    
    // Test that I can actually retrieve a record
    const r = await client.items.find(records[0], {
        version: 'published'
    });
   console.log(r); // It prints out information, it finds the record
     
     // This bulkDestroy does not work and dies with 404
     // await client.items.bulkDestroy({
    //   items: records
   // });

   //This also doesn't work with just a single record, dies with same error
   client.items.destroy(records[0]).catch(e => console.error(e));

}

main();

Not sure what I could be doing wrong? datocms-client used is 3.4.7 .

Any ideas?

hello @technology I’ve tried your script with a token of mine and it worked perfectly.

Can you please send me over at support@datocms.com your token and model type so that I can double check running the full script and seeing the error?

Thanks!

1 Like

Hi @mat_jack1 ! Thank you for the response. After some resting time, finally realized what my mistake was.

I misinterpreted and was using the wrong API to delete records. Instead of using bulkDestroy or destroy, I was supposed to update.

Thank you!

1 Like