mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM
https://dev.mailjet.com
Other
130 stars 72 forks source link

How to get total count ? #189

Closed mbautista closed 3 years ago

mbautista commented 4 years ago

Hello, I would like to retrieve the total messages count with query parameters. When calling Mailjet::Message.count(params) params are ignored (it returns the whole total count whatever the params). When calling Mailjet::Message.all(params) we only get an array of Message, the Total count is missing. Is there a way to retrieve the total count with params ? NB : The /message end point is limited to 1000 records, so the Total count differs from the array size when > 1000. Thank you :)

xab3r commented 4 years ago

count with parameters isn't supported. You can fetch all messages as you suggested. Check this pseudo code:

while messages.count > 0 {
  messages += Mailjet::Message.all(limit: 1000, offset: n)
  n += 1000
}
mbautista commented 4 years ago

Hello xab3r, Yes, that's what we did for now. Sorry I didn't post the code but it's the same idea as yours. Thank you :)

xab3r commented 3 years ago

Resolved