Data Management

Get Record

Summary

Hey there! In this blog post, we'll dive into the `get record` function in Xano, which allows you to retrieve records from your database tables effortlessly. Let's go through it step by step:

Step 1: Access the `get record` Function

First things first, open your function stack in Xano and navigate to the "Database Request" section. Here, you'll find the `get record` function. Click on it to get started.

Step 2: Select the Table

Once you've opened the `get record` function, you'll be prompted to choose the table from which you want to retrieve a record. Xano will automatically populate your database tables for you to select from. For this example, let's choose the "user" table.

Step 3: Choose the Field to Search By

On the right side of the function, you'll see the "Find user record by field" option. By default, the "ID" field is selected since it's the primary key for most tables. However, you can change this by clicking the dropdown and selecting any other field from the table.

Let's keep it simple and stick with the "ID" field for now.

Step 4: Provide the Field Value

The "Field Value" is the actual value you want to search for in the chosen field. This can be a static value or a dynamic input.

For instance, you could add a table reference input for the "user" table and map the "Field Value" to the "userID" input. This way, you can look up user records by entering their respective IDs.

Alternatively, you could search for records based on other fields like "name" by providing the appropriate input and mapping it to the "Field Value."

Step 5: Customize the Response (Optional)

On the "Output" tab, you can customize the response fields you want to receive. Uncheck the "Customize Response" option to return all fields, or selectively choose the fields you need.

Additionally, you can use the "Add-ons" feature to extend the data of a single API response from different data sources, but we won't cover that in this tutorial.

Step 6: Handle User Authentication (Optional)

If your table requires user authentication and is either the "user" table or references a "userID," you can use the unique ID from the auth token to look up records.

In the "Field Value" input, type `auth` and select `authID`. This way, when you run the function, the token passed through the header will allow you to find the specific user record.

Step 7: Look Up Records by Multiple Parameters

Sometimes, you might need to look up a record based on multiple parameters. In such cases, use the `query all records` function instead of `get record`.

First, change the "Output Type" to "single" to return a single object instead of a list. Then, in the "By Custom Query" section, you can add as many field lookups as needed (e.g., userID, userName, userEmail, etc.).

And that's it! You've now learned how to use the `get record` function in Xano to retrieve records from your database tables. Remember, if you need to look up records by multiple parameters, use the `query all records` function instead, and follow the steps mentioned above.

Happy coding (or should we say, happy no-coding)!

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