Pricing Blog

How to Add a New Field to API Items Before Saving to Variable?

  • dark.yelllw-1377551490310475907

    Dark Yellow

    3 months ago

    Hi everyone,

    I’m working with a Xano API in Toddle that returns a list of items with fields like close_date. I want to add a new field (e.g., relative_time) to each item based on the close_date before saving the results to a variable (Results)

    I have a custom action (ConvertToRelativeTime) that should process the timestamps.
    * But when I use Set: results, it only saves the transformed items, not the full response.

    Here’s an example of one item:

    {
    "close_date": 1748497620000
    }


    I want it to become:

    {
    "close_date": 1748497620000,
    "relative_time": "3 hours ago"
    }


    Any tips on how to do this efficiently in Toddle? Thanks!
    1377551490717057166-Wispr_Flow_hSXcroLZ8g.png
  • filip_dajkovic-1377553768568066130

    Filip Dajkovic

    3 months ago

    This is an example how set variable formula should look like to achieve that, you just need to do the formatting and use formulas in the "value" section in "Set" formula which will set the value you need as "relative_time" or whatever you input in the "path" parameter.
    1377553768295563355-CleanShot_2025-05-29_at_09.43.032x.png
  • dark.yelllw-1377558298097881135

    Dark Yellow

    3 months ago

    Thanks for getting back, @Filip Dajkovic. That makes sense. Though I'm still bewildered as to how I actually convert the timestamp from within the formula since I can't access an action from within a formula, right?
  • 1377558383061762118-image.png
  • filip_dajkovic-1377559913240203499

    Filip Dajkovic

    3 months ago

    You can't access action from a formula, you'll need to make it as a (custom) formula instead. And I think you didn't get the basic structure right, you're setting "relative_time" in array, not in each object inside of the array. I could help you to get it right for your use case, I'll be in the chat room so you can hop in and we can work it out, if you want that
  • andreasmoller-1378083325515661363

    Andreas Møller

    3 months ago

    If the purpose is to convert a date to relative time I would recommend using a formula instead of an action
  • jaycmpb-1378105891030700122

    Jay Campbell

    3 months ago

    This was what we solved when we had that random party and put him at the front of the class. 🤣
    😂1
  • andreasmoller-1378234077152415876

    Andreas Møller

    3 months ago

    Ah!
  • dark.yelllw-1378456378024394894

    Dark Yellow

    3 months ago

    Hey @Andreas Møller why a formula over an action? - interestingly Ive just noticed the action is doing it incorrectly.
  • andreasmoller-1378456947036000449

    Andreas Møller

    3 months ago

    Formulas are for transforming data.

    Actions are for side effects
    🫡1