Filtering external API request results

Options
Liz Anaya
Liz Anaya Member, Administrator

ADMIN

@Yuriy

Below you can find a video explaining how to use the filter Filter to filter the results you are getting from the external API request.

https://www.loom.com/share/3e2d93ada5a047a693a6d51f982cb75b?sid=e10febf6-05e8-40db-bac3-26b2c693320e

Let me know if this points you in the right direction!

Comments

  • Yuriy
    Yuriy Member
    Options

    Hey @lizanaya

    Yeah, I tried to use that filter function but it doesn't work in my case. I just prepared a short video explaining why
    https://www.loom.com/share/e1697c38d5364a7aa30ae490af565ca4

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

    You can access the vars defined in the function stack using the special variable $var. (you can access inputs via $input and the auth via $auth)

    And then there is the additional complexity that you are looking for IDs that are not in your user list.

    Let's combine these ideas. I am freestyling, so there are probably edits you need to make to the below. For example, "fieldname" is the external string-ish field you have on your user table that would match to the list you get from the API call. (Xano table id fields are always integers, so it must be a different field)

    Here's an example of how you would do it:

    return !$var.user_list.some(({fieldname})⇒fieldname == $this.id);

    The exclamation point is "not". That means accept those fields that do not match the following.

    The $var.user_list gets the variable you are looking for.

    The "some" method on an array returns true if it finds an matches (so combined with the !, it means return true if there is no match)

    The callback function on the some is how it evaluates each item in user_list. This will check for the match on fieldname value in that record of user_list matching the id of the item that came back from your API request.

    These kinds of complex "inject a little code" situations are often part of the hardest 5% we work on in State Change recorded and searchable office hours, as well as our loom-enabled forums, where what you did generates these kinds of answers on the regular!