What happens in Xano doesn't in Swagger

Options
I'm not doing something right...  Michael U. helped resolve getting and using a variable created in the function stack (it was an object not a scalar value).  In any case my Xano API functions properly as a POST in the Xano UI.  Jumping over to Swagger and using the same input I get a 500 status error.  Since this is a POST I have to use Swagger to test its functionality; I can't just pop the URL into a browser.
Nothing fancy here, just JSON that generates no errors
[favorites 404 error 04.jpg]But somehow this input generates the error below.
This appears to be my ignorance and not the server; it knows what to expect better than I do.  This same API endpoint works fine in Xano.[favorites 404 error 05.jpg]mydata.art_favorite is 'true' (no quotes) is generating the error.  Stepping back a bit on the responses there is the [object, Object] array that looks suspicious but I don't know how to address that or where.[favorites 404 error 06.jpg]

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    What do your inputs look like at the top of the function stack? I think the shape isn't quite right from the test request. 

    More data would tell, but my first instinct is that I kind of wonder whether mydata is the top level of the POST - e.g the correct shape is: 
    {
      "member_id":123, 
      "artworks_id":435, 
      "art_favorite": true
    }
    (without the "mydata" intermediation)

    Will look again if you post the header! 
  • David Richardson
    Options
    HI Ray

    The Swagger screen looks like this and taking out  the "mydata" intermediation did not change things there.[favorites 404 error 07.jpg]In Xano here is my input screen.  I was told that the two variables "data" in this instance, need to be identical for the API to work.[favorites 404 error 08.jpg]and in the xano input screen eliminating the "data" intermediation throws an error indicating it was not valid JSON.[favorites 404 error 09.jpg]The inconsistency between the Xano  UI and the Swagger UI confuses me.  The Xano code works fine in Xano.  But the API fails loading the web page and in Swagger the API also fails.  The inconsistency makes it difficult to sort out what is happening.  

    I appreciate you looking at this but I feel this is kinda like hooking a racehorse (you) up to a plow (me).  ;o)  Gratitude Ray!
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    Got it. You need to change the name of the function from /update_faves/{data} to just /update_faves. You will then find this payload works: 
    “{
      "data":
      {
        "member_id":123, 
        "artworks_id":435, 
        "art_favorite": true
      }
    }”

    The issue is that the curly brace {data} is called a path parameter, which needs to be a string or a number. The [Object object] you saw was a result of trying to marshal your object into a string for that purpose. As a POST, the inputs can come from either the path parameter (when you have those curly braces), the query string (the part after a ? in a URL) or the body of the transaction itself. You want the latter. This should get you there. 
  • David Richardson
    Options
    I tried that in Swagger and again with no success.  See below[favorites 404 error 10.jpg]I signed up for office hours tonignt
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
     Did you get it sorted out in office hours or offline?
  • David Richardson
    Options
    I'm working through this code in the JavaScript side of things first on the page.  I don't think discussing JavaScript in THIS forum is where it belongs