API to get the teams from the authenticated user's division

Options

I'm building a basketball league SAAS. I want to create a Xano GET endpoint that returns a list of the teams in the division that the authenticated user plays in. I copied the auto-built /team API and called it /teams_in_users_division and added an input called for integer division_id. But how/where do I specify that the division id input will be the division that the authenticated user is playing in? Any guidance would be appreciated. (BTW: weweb front-end, and Xano Auth).

Best Answer

  • fredo22
    fredo22 Member
    Answer ✓
    Options

    Thanks Ray. That worked! Although I'm still too much of a noob to understand why that needs to be a text intead of auth…

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    edited March 2023
    Options

    Here's where Xano gets really awesome. You do this by customizing the functions stack rather than using the automatic one-liner that the auto-built APIs give you. You'll want to:

    1) Make this an authenticated endpoint (gives you access to id in auth)
    2) Fetch the user record (a get record from the user table using the ID from auth, now available in your picklist)
    3) Shift the query all records call to filter based on the division ID from the record you got from the user table
    4) Remove your division_id input - you don't need it anymore!

    Hope this gives you a beginning. You're entering the part where Xano gets cool in my opinion. We work on the parts of our projects that are our hardest 5% in our community and in daily office hours at State Change Pro if you'lre looking accelerate this learning: https://statechange.ai

  • fredo22
    fredo22 Member
    Options

    Thanks Ray! I'll check out State Change!

  • fredo22
    fredo22 Member
    Options

    I tried to create a Get record from User table, but when I open the function to define, I set the 2 dropdowns to Auth ID… then tried run & debug and got this error: “Unsupported parameter reference - xdo.1”. - what did I do wrong??

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

    @fredo22 is this still an outstanding issue for you? The issue is that the field_name version of id needs to be the text "id" - you want to make sure it shows "text" and not "auth" in the corner there. The field_value is set correctly.