Question

I use gem 'sendgrid_toolkit', '>= 1.1.1'. I want to get my daily email sending limit.

Thanks in advance.

Was it helpful?

Solution

Unfortunately, there's no way to get the number of email remaining on your plan with the SendGrid API at present (as a standard SendGrid User). You can, however, use the General Statistics endpoint and it's parameter requests. You may then subtract requests from the number of emails you have in your plan.

Doing so would look something like:

total_credits = 100000
statistics = SendgridToolkit::Statistics.new(api_user, api_key)
stats = statistics.retrieve_aggregate(:start_date => Date.today.beginning_of_month, :end_date => Date.today.end_of_month)
credits_left = total_credits - stats[:requests]

p credits_left

As an additional note, I wouldn't worry too much about going over your credit limit as at present overages are billed at 1¢ per 1,000 emails.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top