Botify LogoBotify
HomeAboutBlogContact

© 2025 Botify. All rights reserved.

    BotifyBotify
    Get Started

    How can we delete items in sanity through code

    If you want to delete many items in one time in sanity through code so apply this method

    user image
    Muhammad yousuf

    .

    Published in Botify

    Jan 10, 2025

    2

    post image

    Delete all items of your project in sanity with Next js

    export const DELETE = async (req: NextRequest) => {
    
      const products = await client.fetch(`*[_type == "type"]`);
    
      const allIds = products.map((product) => product._id);
    
      for (const id of allIds) {
       await client.delete(id);
      }
      
      return NextResponse.json({ products: allIds });
    };