Sendgrid-python: Custom_args not working in V3 but unique_args sends email but not in event_callback.

Created on 29 Aug 2018  路  4Comments  路  Source: sendgrid/sendgrid-python

Issue Summary

I have used sendgrid v3 api for sending emails. As mentioned in documentation of V3 API I use custom_args to get my params in event callback but it shows 400 bad request, while I use unique_args, the email was sent but the event callback does not send my unique_args params.

Steps to Reproduce

  1. data = {"content": [{"value": "dfafds", "type": "text/plain"}], "attachments": [{"content": "UEsDBB......QACAgIAAA=", "type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "content_id": "BqzZqz7LaqO9", "filename": "Contactmanager-company.xlsx", "disposition": "attachment"}], "from": {"email": "[email protected]"}, "personalizations": [{"to": [{"email": "[email protected]"}], "custom_args": {"email_msg_id": 106}, "subject": "daff"}]}

  2. callback data is
    [{"sg_event_id": "aoDNXRAeRuaCAVRiutD-fg",
    "sg_message_id": "epJqlw1JThGw--dDTC1oCQ.filter0099p3las1-8681-5B853F95-29.0",
    "smtp-id": "epJqlw1JThGw--dDTC1oCQ@ismtpd0006p1maa1.sendgrid.net",
    "timestamp": 1535459222,
    "email": "[email protected]",
    "event": "processed"}

Technical details:

  • sendgrid-python Version: master (latest commit: [commit number])
  • Python Version: 3.3
unknown or a waiting for feedback question

Most helpful comment

Thank you @thinkingserious
It worked with string data_types in custom_args.

All 4 comments

Hello @bishnusyangja,

Could you please let me know what the 400 bad request error message is?

Thanks!

With Best Regards,

Elmer

No more information is given when sendgrid response is bad-request.

Exact code I tried:
data = {"content": [{"value": "dfafds", "type": "text/plain"}], "from": {"email": "[email protected]"},
"personalizations": [{"to": [{"email": "[email protected]"}], "custom_args": {"email_msg_id":
106}, "subject": "daff"}]}

url = 'https://api.sendgrid.com/v3/mail/send'
headers = {'Authorization': 'Bearer {}'.format(settings.SEND_GRID_API_KEY), 'Content-Type':
'application/json'}

response = requests.post(url, data=json.dumps(data), headers=headers)
print(response.status_code)
print(response.json())

Response is:
400
{'errors': [{'message': 'Bad Request', 'field': None, 'help': None}]}

Hello @bishnusyangja,

What is the result of print(response.body)?

Also, please try:

"email_msg_id": "106"

Thanks!

With Best Regards,

Elmer

Thank you @thinkingserious
It worked with string data_types in custom_args.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hanhaa picture hanhaa  路  4Comments

hugomallinson picture hugomallinson  路  3Comments

sohamnavadiya picture sohamnavadiya  路  4Comments

thinkingserious picture thinkingserious  路  5Comments

danielghurley picture danielghurley  路  4Comments