Receiving an error with SendGrid template code

I’ve followed CodeQueen’s tutorial ( https://support.totallycodable.com/en/article/send-email-notification-using-sendgrid-npm-and-wix-code ) to trigger e-mails upon submission of a custom form, but am receiving the following error in the console:

“Hook afterInsert for collection WorkshopForm result ignored! Expected hook result to resolve to an object with an ‘_id’ property, but got [Undefined]”.

This is my data.js code (I used my own e-mail addresses under “to” and “from” to test it out):


…and my SendGrid template has the variables {{firstName}}, {{lastName}}, and {{email}} in the body, which are also field names in the data collection.

I’ve set up the hook for the data collection as described, and the permission is set to “Form Submission”. Does anyone have any idea what the problem might be?

You’re missing return item; in line 16

Thank you for the response - I tried doing that and I’m no longer getting the error, but unfortunately I’m still not getting an e-mail on form submission. I’ve double checked to make sure I’ve done everything mentioned in the tutorial, so please let me know if you have any clue why it wouldn’t work!

  1. Make sure the API key and the template key are correct.

  2. Make sure the package is installed.

  3. Check the email spam folder and see if it’s there.

  4. Go to SendGrid statistics and check the status.

There was a space at the end of the template ID and before the apostrophe (it’s visible in my code image) - fixing that did it.

Thank you so much. It always feels good when there’s a simple solution like this.