Post more than one value

  • petershaw99-1295716763157135360

    PeterShaw

    6 months ago

    Is it possible to post more than one value with one API call?

    I thought of creating an array and pass this array to Supabase. If this is the way to do it, how can I add values to this array?
  • burner918-1295729492794278018

    Sean

    6 months ago

    You could create an object and package all those values into into it e.g.
    { "name": "John", "email": "john@email.com} and set that object as the body of the API post request.
  • petershaw99-1295731349168193557

    PeterShaw

    6 months ago

    Thanks @Sean How do I add values from an input or select into the object?
  • plusmin-1295735462283055164

    Armand

    6 months ago

    @NoCode ProCode does that in this video: https://www.youtube.com/watch?v=nYyEwOoiyrw
    ❤️1
  • burner918-1295735528431550515

    Sean

    6 months ago

    You could create a variable of type object and say you call it "person". When you create it, you can set the keys name = empty and email = empty. Then on your name input element you can set an event (I use the input event) and in the formula editor, use the set node to set the name key of the person object to whatever value is emitted from the element
    1295735527445893241-
    1295735528183959602-
  • petershaw99-1295739837671800852

    PeterShaw

    6 months ago

    Got it thanks 🙂

    But what if I want to pass the same type of values? In my database there is a field color. As a user you have 3 inputs and can theoretically insert 3 different colors. I want to pass all 3 colors at the same time instad of one by one.
  • burner918-1295741635111551018

    Sean

    6 months ago

    They will all be passed at the same time if they're part of the object "userColor". The principle remains the same. You just set events on each of the input elements such that when the input of color1 is changed, an event sets the "color 1" key for the "userColor" object to whatever was in that input. Then when the user clicks and selects a color for input color2 element, an event on that element sets the "color 2" key for the userColor object and so on. Basically, you're simply building the object (and each of it's keys) to the colors from each of the three inputs and then passing that "userColor" object as the body of the API request. The "userColor" object will be sent as one thing -- it just so happens to have three sub-items within it that can be extracted by your backend.
  • petershaw99-1295750889705050168

    PeterShaw

    6 months ago

    I did it as you described it but unfortunately in the api call it only outputs one of the values
    1295750889415508008-
  • Maybe it is an issue because all values have the same key?
  • burner918-1295753610008854538

    Sean

    6 months ago

    Yes, that is why. Try setting unique keys (color1, color2, color3). Also, the way you set up the initial object is fine -- you're assigning each key with an initial value. But when you want to modify the value of a key, say the 'color1' key of you should use the set node to set the key in an object. In the image (1) Sets the object ("person") whose value I want to edit (2) In the formula editor, I set what I want it to be set to. But "person" isn't a primitive -- its an object -- it has more stuff inside it that (3) I need to use the set node to modify. In the set node, I indicate the path (key), I want to set inside this (person) object -- the key or path is 'name' and (4) I set the 'name' to the value emitted by the input element.
    1295753609765720085-

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.