Filter API results Server Side

CHANGED TO BUG REPORT AS IT APPEARS IT’S A BUG WITH .where in PHP

I’m making a call to Google Photos to get a list of Albums. The Google Photos API has no way to filter this call so I need to filter the results in the server connect. In my case I want to filter it by the title starting with TT. I tried using api.data.albums.where(‘title’, ‘startsWith’, ‘TT’) as the Expression in a repeat but that throws an error: “message”: “Undefined index: title”. Same error happens if I try to Set Value as an array.

I can do the repeat on the full api data set and use a condition to set a value if the title starts with TT but then I end up with a dataset with lots of empty records. I can get around this by filtering on the client side but I’m wondering if there’s a way to do this server side. Also curious if there is a reason for the repeat to return empty records at all.

Thx.

You’re doing everything right :man_shrugging:

  1. You’re going to need the post the result of api.data to confirm everything’s right
  2. You’re going to need the post a view of your Steps

Good to know!!! I thought I was loosing my marbles. :slight_smile:

FWIW I also tried data.albums.title and albums.title

Thx.

On your Repeat is the Output checkbox ticked and the Set Values as well?

It’s actually throwing the error in the above at the Set Value line. I can disable the repeat and it still throws the error.

Could you disable the Set Value before the Repeat for the time being? Let’s test if the Repeat works

Repeat works fine like this…

But throws the error like this…

I just noticed it deletes my Output Fields and clears that list when I add the where formatter. I tried Exclude but that didn’t work.

Unfortunately, I don’t know how to help further. At this point you’d have to stick with the Repeat that works, and if you have free time open a bug report about the .where formatter failing. I tested it here on latest NodeJS and it seems to be working fine :man_shrugging:

Thanks for trying! Interesting that it’s working on NodeJS but not PHP. I’ll go ahead and change this to a bug report.
Happy New Year!

1 Like

Happy New Year Heather,
Just for the sake of ruling out PHP, I tried the startsWith filter on a PHP project and it works fine for me:

May I suggest trying (as I wonder if it is struggling with nested data for some reason)

  • Use a set value to assign the albums property (api.data.albums) - you could output it too to make sure the data is being found correctly
  • Apply the where formatter to that item in another Set Value

Happy New Year Ben!

It seems to be duplicating the albums. I can’t select or delete that second set. And I get the same error using a subset of api.data or api.data.albums.

I also get the same error if I try to use where on the repeat.

I’m going to try recreating the whole thing in a new server action. Maybe this file just got corrupted somehow.

I meant something like this:

By outputting, you can see what is picked up in the first Set Value - just to make sure the correct data is referenced

That being said, there’s nothing obviously wrong with what you have done so it may not throw too much new light…

That’s what I did.

Sorry - it joust looks different on your screenshot

If you use the 2 set values like I have posted above but disable the second (leaving just the one set to api.data.albums) what do you get in your browser console when it is output?

Yeah - I didn’t post pics of every iteration I tried. Sorry about that.

I’ve now created a whole new file and set it up as you did above.

If I disable api_filtered this is the output…

But if I enable the api_filtered it throws the same error again.

Note: I also tried renaming the title column but got the same result.

Interestingly, when I change the filter to the id field it works fine!

Is it possible for an album to not have a title?

Make a duplicate of dmxConnectLib/lib/formatters/collections.php (just so you can easily revert back if you need)

(in the original collections.php) Alter the foreach loop in the formatter_where function (line 28) to:

foreach ($val as $key => $obj) {
        $o = (array)$obj;
        if(isset($o[$prop])){
        $v = $o[$prop];
        $add = FALSE;

just add the if(isset(... line
and add a closing curly brace to close the isset if block (approx line 78):

if ($add) {
            $filtered[] = $obj;
        }
        }
    }

    return $filtered;

Actually yes. Interesting thought. In my condition to set value in the repeat I had to add title != null because it was adding the last title value to an album without a title.

Unfortunately going through and giving titles to the albums didn’t change the error.