Home > Net >  SendGrid Email Activity API with no limit returns BadRequest
SendGrid Email Activity API with no limit returns BadRequest

Time:09-26

Is there any way I can get the email activity from my API key without a limit? According to the documentation, the limit parameter is not required, but any time I don't specify a limit I get a BadRequest response.

  public async Task<SentEmailModel> GetEmails()
        {
            var client = new SendGridClient("SENDGRID_API_KEY");
            var queryParams = @"{
                'limit': 100 //I dont't want to specify a limit, since I want to get the full list
            }";
            var response = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: "messages", queryParams: queryParams);
            if (response.IsSuccessStatusCode)
            {
                var responseString = response.Body.ReadAsStringAsync().Result;
                var responseMessages = JsonConvert.DeserializeObject<SentEmailModel>(responseString);
                return responseMessages;
            }
            return null;
        }

CodePudding user response:

As you said, the docs say the limit parameter isn't required, but the API returns an error when you don't provide it. I have notified our docs team to fix this.

However, if the limit parameter were optional, it would default to 10 which wouldn't achieve the result you desire. Some of the APIs you can paginate over to get all the data, but this API does not support pagination.

If you need to go beyond the 1000 limit, I'd recommend setting up the event webhook to receive the data in realtime, and retain the data in your application.

  • Related