sendgrid-python icon indicating copy to clipboard operation
sendgrid-python copied to clipboard

Cannot submit multiple categories to Categories Statistics endpoint

Open chrishenry opened this issue 10 years ago • 5 comments

Issue Summary

When using the client to get statistics for categories, it's not possible to submit multiple categories.

Steps to Reproduce

fun_stats = sg.client.categories.stats.get(query_params={
    'start_date': "2016-06-30",
    'categories': ['category1', 'category2'],
})

The above code makes a GET to this URL. Sendgrid returns a 404 for this request.

https://api.sendgrid.com/v3/categories/stats?categories=[u'category1', category2']&start_date=2016-06-30

When the correct behaviour is a GET with both category1 and category1 as values to categories. Sendgrid returns the expected response.

https://api.sendgrid.com/v3/categories/stats?categories=category1&categories=category2&start_date=2016-06-30

This seems to be a bug, as the Sendgrid docs clearly state sending multiple categories is supported, and there doesn't seem to be a way to do that with this client.

I believe the issue is actually here, in the python-http-client lib. urlencode should be passed a second parameter, (doseq), which will correctly format multiple values for parameters. (urlencode docs)

Technical details:

  • sendgrid-python Version: 3.0.0
  • Python Version: 2.7

chrishenry avatar Jul 02 '16 04:07 chrishenry

Solved with https://github.com/sendgrid/python-http-client/pull/11

thinkingserious avatar Jul 08 '16 23:07 thinkingserious

While multiple categories can be passed for Category Statistics, passing any more than 10 categories in the params leads to a 400 Bad Request error.

Code to Reproduce

cats = ['T1', 'T2, 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'T10', 'T11']
params = {'categories': cats,'start_date': '2017-05-01', 'end_date': '2017-09-01', 'aggregated_by': 'day',}

Is there a way this limit can be lifted?

Thanks!

ninadamondikar avatar Sep 10 '17 19:09 ninadamondikar

Hi @ninadamondikar,

This is a limitation of the API. I will pass along your feedback to the product team. Could you please describe your use case?

With Best Regards,

Elmer

thinkingserious avatar Sep 11 '17 21:09 thinkingserious

Hi -

My use case is that I am looking to export a dataset with all the stats for every single email category in my SendGrid account (which at this point is over a 100). This dataset will be used for internal reporting and analytics on email performance by being imported into a business intelligence software.

Currently, I have a workaround for this: making multiple calls offsetting each call by 10 starting from 0 and then combining the output. However as the number of categories keeps increasing lifting the cap on number of categories will help streamline the code.

Thanks! Ninad

ninadamondikar avatar Sep 12 '17 01:09 ninadamondikar

Hello @ninadamondikar,

Do you mind opening up a new issue specifically for this request? I'd like to try and get better visibility to increase its priority.

Thanks!

With Best Regards,

Elmer

thinkingserious avatar Sep 12 '17 20:09 thinkingserious