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

不打扰是莪最后的温柔 提交于 2019-12-10 12:25:12

问题


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

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/22779219/how-to-get-available-emails-quota-in-sendgrid-through-marketing-email-api-in-rub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!