PricingDocsAcademy
Bluesky ...
Wed, Dec 11, 10:18 PM

Quite a strange behavior with my POST request

  • Sam B

    12 days ago

    I have a POST request where I send multiple variables to my Xano backend. I send it as an Object where I set variables along with appropriate values. I send 8 variables in the BODY, but when I goto xano, I see only 7 and also not the values I intend to see. For eg., all of them should have String values, but for 2 of them I see as objects.

    I really am confused as to how this can happen. Has anyone had such a situation?
  • Max

    12 days ago

    Can you share the setup (body) of your API call and all info that might be relevant to solve this? Screenshots or short video. Otherwise, it is hard to say what is going on
    πŸ‘πŸ½1
  • Sam B

    12 days ago

    https://streamyard.com/tiznay9w9kxt - Here's a quick one where I show the problem.
  • Tom Ireland

    12 days ago

    Not to steal Max's glory on supporting you with this one, but I couldn't help observe a couple of things in your video:

    * The display_picture value in the object is showing undefined, which could explain why that value is not being sent back. Likely due to waiting for a result from the API, so would be expected when not called.
    * Your second API call in your workflow is run in parallel with your first API call, which could introduce a race condition. It would be better to run the second API call on success of the first one.
  • Tom Ireland

    12 days ago

    Re: the last point, it'd be the same for both subsequent API calls in your switch statement - do them both on success of the first. It also means you can handle errors for the first and not execute the second.
  • /attachments/1312001241664192553/1312032566982873158/image.png

    Sam B

    12 days ago

    Thanks @Tom Ireland for the quick reply.

    What I did now was to set those strage paths on the API's success event and I set a variable with error message in case of error.

    In Form submit siwtch flow, I call the second API on the success of the first.

    The first one uploads images without any hassles and returns the path as desired. Now the second POST API is not being invoked at all.
    image.png
    image.png
  • Tom Ireland

    12 days ago

    No problem - happy to help where I can. If the second API is not being called following the first one, it would suggest that no result is being returned from the first one in order to call the second one. Or the result is not returning success status code (normally 200), which is unlikely.

    I'd advise double-checking in Test mode to see if the first API is being called and return the correct response and then do something like set a test variable to "success" on success of the first call. This would confirm that the first API call is working. If so, the second one should be called.
  • Oh, hang on. Do you have an 'On success' condition set on the first API in the 'Events' tab? I wonder if that might conflict with the 'On success' in the workflow.
  • /attachments/1312001241664192553/1312047708483354654/image.png

    Sam B

    12 days ago

    Alright, followed your advice and made some changes. Infact, I wanted to take ons tep at a time, So I deleted the Switch flow and instead want to see whether a default flow on form submit works.

    There is definitely some progress, but not 100% yet.

    What I do now is, I call the first API on form submit and on success, I set the storage path of first variable, sleep for 600 milliseconds, then set the storage path for second, then sleep and so on. Finally I call the 2nd API.

    What happens now is, in the 2nd API, only the 1st storage variable is set and the other two goes as null. Hence it fails.

    I gave Sleep thinking probably the 2nd API is invoked even before the values are set. Looks like it's something else.

    Ooof!
    image.png
    image.png
    image.png
  • Tod

    12 days ago

    Great energy @Sam B! Your continuous contribution to the toddle Community just made you advance to Community Level 7!
  • Tom Ireland

    12 days ago

    @Sam B - Good to hear you're making progress. Have you tried preventing the second API call temporarily in your workflow and looking at the object it should send via the second API's body tab after the first API call? Even better, output the second API call object (the way it should look before it's sent) to the page in a string to see what the values are. If the two values are null at that point, something is not right following the first API call.

    I'd be happy to have a peek at your project if you'd like but appreciate if it's private, etc.
  • /attachments/1312001241664192553/1312103983313322054/image.png

    Max

    12 days ago

    Thank you for the video! Here are a few points:

    Remove the sleep functions. They are causing an issue where only the logo_storage_path is being set. While you wait 600ms to set the path, the API is called anyway without waiting. The wait only works if you place it in the "tick" callback from the sleep node, but you don't need a sleep function at all.
    I recommend consolidating everything into one flow. Currently, you're setting the paths in the "global" onSuccess of the API, with the rest in the local onSuccess within the workflow. It would be better to do everything in the local one: set each variable, then call the API.
    The display_picture wasn't set because you referenced it as an object when it should be handled as a string (see screenshot)
    image.png
  • Sam B

    9 days ago

    Thanks a lot @Tom Ireland and @Max for your suggestions. Let me try them in a bit and post an update.

    I was so frustrated with the bug that I gave it a break over the weekend 😒 hence the late response!
  • Tom Ireland

    9 days ago

    No worries. Let us know how you get on. πŸ‘πŸ»
  • Sam B

    8 days ago

    @Tom Ireland , @Max - Made some progress, thought of sharing it, I recorded a quick 3 min video and here's the link: https://streamyard.com/zcbk7fut3xth

    Long story short, if I perform the step in test mode, the values are passed to the API whereas if I try in Preview mode or Publish the app and test, it's still null.

    I'll troubleshoot further to see what is causing this.
  • /attachments/1312001241664192553/1313505474578087986/image.png

    Max

    8 days ago

    This workflow won't work that way. API 2 is called at the same time API1 is called. That is why your values are null. Everything you need to do after the success of API1 has to go in the "On success" path.
    image.png
  • Sam B

    7 days ago

    OMG, it worked @Max . Thank you sooo much, you literally saved my day!

    I got a questions on the working of the workflow though, so when will it execute sequentially?
  • Max

    7 days ago

    Nice!
    They always execute sequentially. But some nodes work asynchronously. That means that they are all called in sequence but the result of node1 might not be available in node2. Those nodes have callbacks: On success, on error, tick...
  • Sam B

    7 days ago

    I see, alright. Thank you so much again!

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.