How to update a record in a POST call that has multiple inputs and I want to be able to pass only th

Options

Currently I have a POST endpoint that has several inputs and I would like to be able to pass to the API only the input I want to update.

Example:


API inputs: email, name, phone

Body request: {"name": "User name here"}


If I execute the call in the example above, the name field will update. However, the other two input fields will also be updated but with NULL values. In the example, I would like to update only the name field and the others remain at the same value they already have.

Tagged:

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Partial updates are a common bugaboo around here. There are a few ways of doing this:

    One is to get the old version fo the table, apply updates to that object in the function stack, and then run an update with those value.

    Another is to if-then your way through each field and do separate edit record calls for each of the fields.

    Yet another is to abandon the partial update and make it part of your API that updates are always record-wide. Then it's up to your front-end to do the mapping by applying a get call before running the POST. (A number of b2b APIs work this way for complete reliability)

  • LeBuick
    LeBuick Member
    Options

    It seems to me that all these approaches are not very efficient. Either you are forced to send redundant data or you need to add a lot of logic to the API endpoint. We are planning to work with tables with many fields and thus this problem will become a serious issue. I feel it would make more sense that Xano will in future support partial updates. Is there any sign this will be coming at some point?

  • Lefteris - blupry.com
    Options

    Hello @LeBuick,

    Replying to you since the original post have been around for a long time…

    If you are facing the same problem, then I guess using an if-then statement alongside with the is_null filter is the way to go for your implementation.

    The filter is used as such:

    Apply it on your input values and you should be fine!

    But it is worth mentioning that most of the times these types of configurations should be handled in the frontend of your application.