How to account for an empty value?

Options
So I've got an enternal API that I'm pulling data from and because there are multiple pages of data in these calls I will need to do some pagination.

This particular API I'm working with has a field that they print in the API called "nextCursorMark" with a value next to it. It's basically the bookmark ID to tell the next API call where to start.

When it gets to the point that we're on the final page of data, the "nextCursorMark" value will be blank.

In my Conditional statement, I need to tell Xano that when the "nextCursorMark" value is empty, stop looping.[image.png]My question is for that "match" would I use the null function or would I just leave it empty? Unlike other APIs I've seen in examples, this particular API does not print anything like "null" on that final page, it just leaves it empty.

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    you can use a filter on the left hand side, like is_empty. Then test that being equal to (bool) false to confirm the member doesn't have anything. 

    But sometimes it does have something that is not exactly "nothing." Or maybe the member doesn't exist. Both of these would require a different treatment. Maybe a screenshot of what comes back from the external service might give a little clarity to either correct the foregoing or confirm that it will set you right. 
  • Brandon Hassler
    Options
    Appreciate the reply! Here is the exact wording from the official documentation of this specific API:
    [image.png]I know in Bubble when running a looping workflow to pull data on this API the logic was basically "if 'nextCursorMark is empty, end the workflow" and it would work. So my assumption is that the value is empty, but perhaps Bubble was doing some behind-the-scenes magic.

    I'm trying to figure out how to "skip ahead" to see what it would actually print for me but can't figure out how.

    Normally I would just test out a few theories but what I don't want to have happen is I accidently create an endless loop of API calls in the process.
  • Brandon Hassler
    Options
     So I've been messing around with this and I can successfully page through all the pages before the workflow ends. However, it's not ending the way it should, it's ending because what happens is that field just disappears all together! This causes an error because when my logic goes to check and see if there is a value that exists, it has no field to check.

    Here is a screenshot of my workflow:[image.png]Before the loop, I set my cursorMark variable as * to start at the beginning of the API results.

    After pulling the API, Step 2.2 creates a variable that checks the value of the "nextCursorMark" with an isempty filter. For this step, I don't care what the value is, I just need to know if the value is there.[image.png]Eventually we hit that last page of the API and the logic goes to read the value of the cursor (Step 2.2 again) but this time it can't even find the field in the data, therefore we get an error and the loop (thankfully) shuts off.

    So techincally it works, as I check my database and have all the results from all the pages, I just want it to end correctly 😅
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
     One thing you can do to prevent the infinite loop is make a counter variable to form a literal circuit breaker. Create the variable outside of the while loop and give it a value of 0. Each time you go through your "while" loop, increment that value by one (use the update variable function, and set it to itself with a filter of add and 1). Then make an "if" statement to check the counter. If it is greater than a certain amount, say, 20, then "break" out of the loop. 
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    Another technique to find out what this looks like: I would also try just searching something that doesn't have more than a page of data - that way you will get just one page and see what it looks like when nothing follows. 
  • Brandon Hassler
    Options
     That's what is weird, I've tried this on two separate calls and it still gives me a value. For example, here is the result for a call that only returned 18 products on 1 page:[image.png]Yet, on Best Buy's own documentation, it says "When you reach the end of the cursor marks, you will receive an empty result. "

    But clearly it dissapears because when I run it through the full loop eventually it breaks as it cannot map to the field anymore 🤷‍♂️
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    docs are imperfect. Embracing that makes everything else easier.

    As for the break: The function errors out on a “cannot find” error or your break statement succeeds?
  • Brandon Hassler
    Options
     well, looks like you are right about documentation being wrong 😂

    First off, the "circuit breaker" idea was genius. Already saved me from a few slaps on the wrist from Best Buy. Turns out what was causing the workflow to eventually fail leading to missing fields was because it was looping so fast after it was done saving products that I would exceed the rate limit and get a 403 error.

    After some digging in the debug mode I found that was was happening was once the API passed through all of the pages with products instead of passing no value it would just repeat the same "nextCursorMark" value.

    So I just adjusted the logic and instead of looking for an empty value, it just compares it to the previous value and if it's the same, it breaks out of the loop.

    Now it works great! Appreciate the help!
  • Ambroise
    Ambroise Member
    Options

    I'm also struggling with checks for Empty and NULL.

    I wish there were simpler operators like "Is empty", "Is NULL", etc.
    Not sure how to achieve that.