Filter emails by which have empty metadata

Hello,
I’m building an email pipeline using the Nylas. I process them and then mark key1: ‘processed’ in the metadata.

Now I want to filter the emails without any value set in key1. Any pointers on how to achieve this?

# 1. Request messages with headers included
metadata = {'key1': None}

messages_response = nylas.messages.list(
    identifier=grant_id,
    query_params={'metadata_pair': metadata, 'limit': 200}
)
print(len(messages_response.data))

The code above returns 0 emails.

@sam, @ram anyone?
Can you please assist with this problem?

Apologies, I am will get back to you with an answer shortly. I am looking into this.

Unfortunately, we don’t support negative search for metadata at this time.

My recommendation would be to fetch the data first and then filter it server-side. From a user experience perspective, I’d suggest using infinite scroll with slight over-fetching or automatically fetching the next batch if all items are filtered out, to avoid displaying empty pages.

We recommend filing a feature request with our Product team to express your interest and use case here: https://feedback.nylas.com.