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.
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"}]}
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"}
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.
Most helpful comment
Thank you @thinkingserious
It worked with string data_types in custom_args.