Reputation: 11
I'm using Amazon.SimpleEmailV2 SDK to utilize the SuppressedList in my service. When i'm trying to retrieve data from the Suppress list my initial request works as intended, I get my result with a nextToken indicating that there are more results to fetch.
The nextToken is then used in a second request to fetch the remaining data. On the second request however, I get the following error:
Amazon.SimpleEmailV2.Model.InvalidNextTokenException: 'Token is invalid.'
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.<HandleExceptionAsync>d__2.MoveNext()
at Amazon.Runtime.Internal.ExceptionHandler`1.<HandleAsync>d__6.MoveNext()
at Amazon.Runtime.Internal.ErrorHandler.<ProcessExceptionAsync>d__8.MoveNext()
at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()
at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
at Amazon.Runtime.Internal.Signer.<InvokeAsync>d__1`1.MoveNext()
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.<InvokeAsync>d__2`1.MoveNext()
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.<InvokeAsync>d__2`1.MoveNext()
at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()
at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()
at Messenger.Providers.SuppressionListAdapter.<GetSuppressedListAsync>d__3.MoveNext() in C:\repo\Messenger\Messenger.Business\Providers\SuppressionListAdapter.cs:line 35
The code we've built looks like the following:
public async Task<List<SuppressedListResponse>> SearchSuppressedListAsync(string searchString, List<SuppressedListResponse> recipients, string nextToken = null)
{
var response = await _ses.ListSuppressedDestinationsAsync(new ListSuppressedDestinationsRequest
{
PageSize = 100,
NextToken = nextToken,
StartDate = DateTime.MinValue,
EndDate = DateTime.UtcNow.AddDays(1),
Reasons = new List<string> { "BOUNCE", "COMPLAINT" }
});
recipients.AddRange(response.SuppressedDestinationSummaries
.Where(x => x.EmailAddress.Contains(searchString))
.Select(x => new SuppressedListResponse
{
EmailAdress = x.EmailAddress,
Reason = x.Reason,
LastUpdated = x.LastUpdateTime
}));
if (!string.IsNullOrWhiteSpace(response.NextToken))
{
return await GetSuppressedListAsync(recipients, response.NextToken);
}
return recipients;
}
Which in turn calls the following method:
public async Task<List<SuppressedListResponse>> GetSuppressedListAsync(List<SuppressedListResponse> recipients, string nextToken = null)
{
var response = await _ses.ListSuppressedDestinationsAsync(new ListSuppressedDestinationsRequest
{
PageSize = 100,
NextToken = nextToken,
StartDate = DateTime.MinValue,
EndDate = DateTime.UtcNow.AddDays(1),
Reasons = new List<string> { "BOUNCE", "COMPLAINT" }
});
recipients.AddRange(response.SuppressedDestinationSummaries
.Select(x => new SuppressedListResponse
{
EmailAdress = x.EmailAddress,
Reason = x.Reason,
LastUpdated = x.LastUpdateTime
}));
if (!string.IsNullOrWhiteSpace(response.NextToken))
{
return await GetSuppressedListAsync(recipients, response.NextToken);
}
return recipients;
}
I've tried to upgrade the SDK to the latest stable version which did not give me the expected result. I've also tried to limit the pageSize also without any progress.
Upvotes: 0
Views: 43