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

How to Receive Custom Arguments in Event Webhook

Open KentaYamada opened this issue 1 year ago • 0 comments

Hi, all.

I would like to set custom arguments in the request using the Node.js SDK and receive them in the Event Webhook, but I'm unable to receive them correctly. Could you please provide guidance on how to implement this?

Package versions

  • node: 18.20
  • @sendgrid/mail: 8.1.3

source code (typescript)

// Send email
const service = new MailService();
service.send({
   from: `Cafe de Gamoyon<${process.env.FROM}>`,
   to: payload.mail,
   bcc: bcc,
   subject: mailTemplate.subject,
   text: text,
  // is that correct ?
  customArgs: {
      mail_notification_id: mailNotificationId,
    },
});

// Define event webhook payload type
type SendgridEvent = {
  email: string;
  timestamp: Date;
  "smtp-id": string;
  event: string;
  sg_event_id: string;
  sg_message_id: string;
  category?: string | string[];
  response: string;
} & Partial<Record<string, string>>;

expected

{
  "email": "xxx",
  "timestamp": "xxx",
  "smtp-id":  "xxx",
  "event": "xxx",
  "sg_event_id": "xxx",
  "sg_message_id": "xxx",
  "category": "xxx",
  "response": "xxx",
  "mail_notification_id": "xxx"
}

actual スクリーンショット 2024-10-23 19 11 48

When I looked at the sample code, custom arguments were set in the personalizations. Is this the only way to receive them in the Event Webhook? https://www.twilio.com/docs/sendgrid/for-developers/tracking-events/event#custom-arguments

KentaYamada avatar Oct 23 '24 10:10 KentaYamada