how to get available emails quota in sendgrid through marketing email api in Ruby on Rails

StackOverflow https://stackoverflow.com/questions/22779219

  •  25-06-2023
  •  | 
  •  

سؤال

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

Thanks in advance.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top