How to associate sendgrid webhook sg_message_id to sent mail?

chaintng picture chaintng · Nov 12, 2015 · Viewed 8.3k times · Source

Sendgrid webhook has sg_message_id But the response of Web API v2 when sending mail doesn't have sg_message_id. In fact, there is only message showing only success or failed.

So, how do i associate between sent mail and the webhook callback?

I have check the past questions in SO but it doesn't provide be the solution for this.

Thank you.

Answer

Dmitry Polyakovsky picture Dmitry Polyakovsky · Dec 8, 2015

You can use unique arguments. Take your unique ID (like primary key) and give it to sendgrid API during sending email. You will get it back in the event webhook.

https://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html