PricingDocsAcademy
Bluesky ...
Wed, Dec 11, 9:54 PM

Post more than one value

  • PeterShaw

    1 month 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?
  • Sean

    1 month 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.
  • PeterShaw

    1 month ago

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

    1 month ago

    @NoCode ProCode does that in this video: https://www.youtube.com/watch?v=nYyEwOoiyrw
    ❤️1
  • /attachments/1295716763157135360/1295735527445893241/image.png

    Sean

    1 month 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
  • PeterShaw

    1 month 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.
  • Sean

    1 month 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.
  • /attachments/1295716763157135360/1295750889415508008/image.png

    PeterShaw

    1 month ago

    I did it as you described it but unfortunately in the api call it only outputs one of the values
  • Maybe it is an issue because all values have the same key?
  • /attachments/1295716763157135360/1295753609765720085/image.png

    Sean

    1 month 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.

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.