Tutorials

Common Xano Roadblocks for Beginners

Building applications with Xano's no-code platform can be a game-changer for those with limited coding experience. However, as with any new tool, beginners may encounter certain roadblocks. In this article, we'll guide you through some of the most common challenges and provide step-by-step solutions to help you overcome them.

1. Working with Loops

One of the biggest challenges beginners face is working with loops, especially when iterating through a list of objects. The most common mistake is not referencing the correct variable within the loop.

Here's an example: Let's say you have a table of products, and you want to increase the price of each product by $5.

  1. Create a new API endpoint and query all records from your products table.
  2. Add a forEach loop to your function stack. Under "Data Manipulation," choose "forEach Loop." Select the list you want to iterate through (products) and leave the variable name as item.
  3. Inside the loop, add an "Update Variable" step. This is where the common mistake happens. Instead of selecting products.price, you need to select item.price because the loop is temporarily storing each object in the item variable.
  4. Add a filter to item.price to increase the value by 5 (e.g., +5).
  5. Save and run your API endpoint.

If you encounter an error like "numbers are required for mathematical operations," it's likely because you're trying to update products.price instead of item.price. Always make sure to reference the correct variable within the loop.

2. Ensuring Valid Data Types

Another common roadblock is failing to ensure valid data types when setting up function stacks. This can lead to errors and unexpected behavior.

For example, let's say you want to update the prices in your products table again, but this time, you accidentally enter the variable as a text string instead of selecting it from the dropdown.

  1. In your function stack, clear out the "Update Variable" step from the previous example.
  2. Instead of selecting the variable from the dropdown, type item.price directly into the input field.
  3. Add a filter (e.g., +5) and save.
  4. Run your API endpoint.

You'll likely encounter an error because the input is treated as a text string instead of a variable. To fix this, always use the dropdown to select variables and ensure the correct data type is displayed (e.g., "var" for variables).

3. Using the Correct Input Type for File Uploads

When working with file uploads, such as user profile pictures, it's crucial to use the correct input type. Using the wrong input type can lead to errors like "value is not properly formed."

  1. In your API endpoint, add a "File Resource" input instead of an "Image" input. The "Image" input only stores metadata, not the actual file content.
  2. Continue building your function stack to handle the file upload.

By using the "File Resource" input, you can upload files either by URL or raw file contents, ensuring a smooth file upload process.

4. Updating Response Variables

Sometimes, you may want to change the name of a return variable in your function stack. However, if you don't update the response accordingly, you'll encounter an error.

  1. In your API endpoint, add a query to fetch records from a table (e.g., stuff).
  2. Rename the return variable in your function stack (e.g., change stuff_1 to stuff).
  3. Save and run your API endpoint. You'll encounter an error like "missing var entry stuff_1."
  4. Go to the "Response" section of your API endpoint and update the response variable to match the new name (e.g., select stuff instead of stuff_1).
  5. Save and run your API endpoint again. The error should be resolved.

5. Working with Relationships and Add-ons

When working with related data in Xano, you may encounter challenges displaying the relevant information. This is where add-ons come into play, allowing you to decorate your responses with related data.

  1. In your database, create a relationship between two tables (e.g., users and stuff).
  2. In your API endpoint, query the records from the related table (e.g., stuff).
  3. Click on the function stack, go to "Output," and select "Add-on."
  4. Follow the prompts to create an add-on:
  • Select the database table you want to add to the response (e.g., users).
  • Choose how you want the data returned (e.g., "Single Item").
  • Specify how to connect the tables (e.g., the user_id field in the stuff table references the id field in the users table).
  1. Save and run your API endpoint.

Now, instead of just displaying the related record's ID, you'll see the actual related data (e.g., user names and email addresses instead of just the user_id).

6. Updating Lists

When transforming or updating data in a list, you'll need to use a forEach loop to update each item individually.

  1. In your API endpoint, fetch a list of records (e.g., stuff).
  2. Add a "Update Variable" step to transform a field (e.g., format the createdAt timestamp).
  3. Save and run your API endpoint. You'll notice that the transformation is applied to the entire list, not each individual item.
  4. To fix this, add a forEach loop around the "Update Variable" step.
  5. Inside the loop, update the variable to reference the loop variable (e.g., change stuff1.createdAt to item.createdAt).
  6. Save and run your API endpoint again.

Now, the transformation will be applied to each item in the list individually, providing the desired output.

By understanding and addressing these common roadblocks, you'll be well on your way to building powerful applications with Xano's no-code platform. Remember, practice and perseverance are key, and don't hesitate to reach out to the Xano community or support team if you need further assistance.

Sign up for Xano

Join 100,000+ people already building with Xano.

Start today and scale to millions.

Start building for free