Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws sesv2 list-contacts returns an empty result when filtering with FilteredStatus=OPT_OUT #8742

Open
delhi09 opened this issue Jun 13, 2024 · 5 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. sesv2

Comments

@delhi09
Copy link

delhi09 commented Jun 13, 2024

Describe the bug

I would like to count OPT_OUT emails in the list management of AWS SES.

I confirmed at least one OPT_OUT email exists using the following command:

aws sesv2 get-contact --contact-list-name=TestContactList --email-address=test@example.com --region us-east-1
{
    "ContactListName": "TestContactList",
    "EmailAddress": "test@example.com",
    "TopicPreferences": [
        {
            "TopicName": "test-topic",
            "SubscriptionStatus": "OPT_OUT"
        }
    ],
    "UnsubscribeAll": false,
    "CreatedTimestamp": "2024-06-05T11:17:46.771000+09:00",
    "LastUpdatedTimestamp": "2024-06-13T12:52:48.739000+09:00"
}

However, the following command always returns an empty result:

aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_OUT,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --no-paginate --region us-east-1
{
    "Contacts": [],
    "NextToken": "***"
}

When FilteredStatus=OPT_IN, the command successfully returns OPT_IN emails as follows:

aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_IN,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --no-paginate --region us-east-1
{
    "Contacts": [
        {
            "EmailAddress": "test1@example.com",
            "TopicPreferences": [
                {
                    "TopicName": "test-topic",
                    "SubscriptionStatus": "OPT_IN"
                }
            ],
            "UnsubscribeAll": false,
            "LastUpdatedTimestamp": "2024-05-23T19:02:54.560000+09:00"
        },
        {
            "EmailAddress": "test2@example.com",
            "TopicPreferences": [
                {
                    "TopicName": "test-topic",
                    "SubscriptionStatus": "OPT_IN"
                }
            ],
            "UnsubscribeAll": false,
            "LastUpdatedTimestamp": "2024-05-23T20:01:50.994000+09:00"
        },
...

Expected Behavior

OPT_OUT emails should be returned as follows:

aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_OUT,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --no-paginate --region us-east-1
{
    "Contacts": [
        {
            "EmailAddress": "test@example.com",
            "TopicPreferences": [
                {
                    "TopicName": "test-topic",
                    "SubscriptionStatus": "OPT_OUT"
                }
            ],
            "UnsubscribeAll": false,
            "LastUpdatedTimestamp": "2024-05-23T19:02:54.560000+09:00"
        },
...

Current Behavior

As described in the "Describe the bug" section.

Reproduction Steps

1.Send an email using the SESv2 API with ListManagementOptions:

import boto3

client = boto3.client("sesv2", region_name="us-east-1")

args = {
        "FromEmailAddress": "from@example.com",
        "Destination": {
            "ToAddresses": ["test@example.com"],
        },
        "Content": {
            "Simple": {
                "Subject": {"Data": "test", "Charset": "UTF-8"},
                "Body": {
                    "Text": {"Data": "test", "Charset": charset},
                    "Html": {"Data": "<div>test</test>", "Charset": "UTF-8"},
                },
            },
        },
        "ListManagementOptions": {
            "ContactListName": "TestContactList",
            "TopicName": "test@example.com",
        }
}
client.send_email(**args)

2.Receive the email in a Gmail client and click the "Unsubscribe" link.

3.Confirm "test@example.com" is saved as OPT_OUT using the following command:

aws sesv2 get-contact --contact-list-name=TestContactList --email-address=test@example.com --region us-east-1
{
    "ContactListName": "TestContactList",
    "EmailAddress": "test@example.com",
    "TopicPreferences": [
        {
            "TopicName": "test-topic",
            "SubscriptionStatus": "OPT_OUT"
        }
    ],
    "UnsubscribeAll": false,
    "CreatedTimestamp": "***",
    "LastUpdatedTimestamp": "***"
}
  1. Fetch OPT_OUT emails using the following command. It will probably return an empty result:
aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_OUT,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --no-paginate --region us-east-1
{
    "Contacts": [],
    "NextToken": "***"
}

Possible Solution

No response

Additional Information/Context

No response

CLI version used

aws-cli/2.16.7 Python/3.11.8 Darwin/23.4.0 exe/x86_64

Environment details (OS name and version, etc.)

macOS 14.4.1

@delhi09 delhi09 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 13, 2024
@delhi09 delhi09 changed the title aws sesv2 list-contacts returns an empty result when filtering with FilteredStatus=OPT_OUT(short issue description) aws sesv2 list-contacts returns an empty result when filtering with FilteredStatus=OPT_OUT Jun 13, 2024
@RyanFitzSimmonsAK RyanFitzSimmonsAK self-assigned this Jun 13, 2024
@RyanFitzSimmonsAK RyanFitzSimmonsAK added investigating This issue is being investigated and/or work is in progress to resolve the issue. sesv2 p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jun 13, 2024
@RyanFitzSimmonsAK
Copy link
Contributor

Hi @delhi09, thanks for reaching out. Since you received a NextToken, I suspect what's happening here is that pagination is taking place before filtering. You're using the --no-paginate flag, so if your OPT_OUT contact is not in the first page of results, getting no results back makes sense. If you remove that, or continue paginating, what's the response look like?

@RyanFitzSimmonsAK RyanFitzSimmonsAK added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jun 20, 2024
@delhi09
Copy link
Author

delhi09 commented Jun 23, 2024

Hi @RyanFitzSimmonsAK , thank you for your suggestion. I tried it, but unfortunately, it didn't change the result.

$ aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_OUT,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --region us-east-1
{
    "Contacts": [],
    "NextToken": “xxx”
}

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 24, 2024
@RyanFitzSimmonsAK
Copy link
Contributor

What if you continue to paginate using the NextToken?

@delhi09
Copy link
Author

delhi09 commented Jul 11, 2024

Hi @RyanFitzSimmonsAK , I apologize for the delay in my response. Thank you for your suggestion.

I tried pagination 10 times as follows. However, the "Contacts" field was empty in all results.

$ aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_OUT,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --region us-east-1
{
    "Contacts": [],
    "NextToken": "xxx"
}
$ aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_OUT,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --next-token xxx --region us-east-1
{
    "Contacts": [],
    "NextToken": "yyy"
}
$ aws sesv2 list-contacts --contact-list-name=TestContactList --filter="FilteredStatus=OPT_OUT,TopicFilter={TopicName=test-topic,UseDefaultIfPreferenceUnavailable=true}" --next-token yyy --region us-east-1
{
    "Contacts": [],
    "NextToken": "zzz"
}

@RyanFitzSimmonsAK
Copy link
Contributor

Are you paginating until there isn't a NextToken in the response?

@RyanFitzSimmonsAK RyanFitzSimmonsAK added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. sesv2
Projects
None yet
Development

No branches or pull requests

2 participants