Data Management

How to delete multiple records through the API

Summary

In Xano, you can easily create an API endpoint that deletes multiple records from your database table. This can be particularly useful if you have a checkbox or similar interface in your application that allows users to select specific records for deletion. Follow these step-by-step instructions to set up this functionality:

Step 1: Create a New API Endpoint

First, navigate to the API section in Xano and create a new API endpoint group. Within this group, click on the "Add Endpoint" button and select "Delete Some" as the operation type.

Step 2: Define the Input Parameter

Next, you'll need to define the input parameter for this endpoint. This parameter should be a table reference to the table from which you want to delete records. In this example, we'll use the "products" table.

  1. Click on the input field and select "Table Reference" from the dropdown menu.
  2. Choose the "products" table from the available options.
  3. Click inside the input field again and change the structure from "Single" to "List".
  4. Optionally, you can define a minimum or maximum number of items in the list.

Step 3: Set Up the Delete Loop

After defining the input parameter, you'll use a loop to iterate through the list of record IDs and delete the corresponding records.

  1. Click on the "Add Operation" button and select "For Each" from the list of operations.
  2. Inside the "For Each" loop, add a "Delete Record" operation by clicking on the "Add Operation" button again.
  3. In the "Delete Record" operation, set the "Field Value" to "item". This will match the current item in the loop (the record ID) to the corresponding record in the table.

Step 4: Test and Deploy

With the API endpoint set up, you can test it by providing a list of record IDs as input. For example, if you want to delete records with IDs 1, 2, 5, and 6 from the "products" table, you would input `[1, 2, 5, 6]` as the input value.

After testing and ensuring that the endpoint works as expected, you can deploy your changes and integrate the API endpoint with your application.

By following these steps, you've created a no-code API endpoint in Xano that can delete multiple records from a database table based on a provided list of record IDs. This functionality can be incredibly useful for applications that require users to select specific records for deletion, streamlining the process and improving the overall user experience.

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team’s progress and create a
backend that will scale for free.

Start building for free