Send Grid and Data Hooks/Variables not working

UPDATE: Hi, I still need help with this. Any help would be wonderful.

Hi,
Continuing with my previous posts about triggered emails I decided to go back to send grid.

I have been using a combination of the following templates:
@yisrael-wix 's: https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-send-email-with-the-sendgrid-npm-interface

@code-queen 's: https://support.totallycodable.com/en/article/send-email-notification-using-sendgrid-npm-and-wix-code
I have been able to successfully send the email, but my variables are not coming through.

This is what it looks like on Sendgrid:

This is what it looks like when I receive it:


I was trying what is here that @yoav-wix , @tomer-wix , and @points seemed to solve https://www.wix.com/corvid/forum/community-discussion/jsw-backend-web-module-issues

This is my current code.
Email jsw:

//-------------Imports-------------//
import sgMail from "@sendgrid/mail";
import wixData from 'wix-data';
import {fetch} from 'wix-fetch';  
// example sendEmail function from: https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail
const apiKey = "SG.";

//-------------Approve Code-------------//
export function sendEmailapprove (recipient, sender, body, businessName,
            member, nonMember, numberOfSpaces) {
sgMail.setApiKey(apiKey);
const msg = {
to: recipient,
from: 'info@sxxxx.com',
templateId:'d-013c14af6fda4a6ea904124e44d61311',
body: JSON.stringify({businessName,member, nonMember, numberOfSpaces})
}
sgMail.send(msg);
}

Page Code: (This is a dynamic page and the email is based on updating the status field)

//-------------Imports-------------//
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import {session} from 'wix-storage';
import wixCrm from 'wix-crm';
import {sendEmailapprove} from 'backend/SHsendEmail';
//-------------Update Code-------------//

$w.onReady(function () {
    $w("#dataset1").onReady(() => {
        $w("#dataset1").setFieldValue("status", $w("#statusDropdown").value);
        $w("#dataset1").save();
    });
})
export function submit_click(event) {
//-------------Approval Email-------------//
if ($w('#businessName').validity.valid === false)
 return;
 if ($w('#email').validity.valid === false)
 return;
 if ($w('#formIdInput').validity.valid === false)
 return;
 if ($w('#statusDropdown').validity.valid === false)
 return;
 if ($w('#statusDropdown') === "APPROVED"); {
      sendEmailapprove (
$w('#email').value,
$w('#businessName').value,
$w('#member').value,
$w('#non').value,
$w('#numberOfSpaces').value
            )
  .then(() => {
 let dataObj = {
                status: "success",
                email: $w('#email').value
            };
        })
        .catch((error) => {
 let dataObj = {
                status: "fail",
                email: $w('#email').value
            };
        })
}
 

Things I have tried

  1. When tired the item.variable (here) shown in @Code Queen Nayeli’s example, nothing happened, and yes, I changed the variables to what is in my dataset.
dynamic_template_data: 
{ name: item.title, 
email: item.email, 
detail: item.detail,   
}, 
}; 
sgMail.send(msg); 
}

When I tried to put “” or ’ around the item. variable it looked like this.


I also tried itemData.Variable and {itemData.Variable}

I also tried itemData.Variable and itemData.Variable


2. I also used this thread by @Tiaan - wix-coders.com:
https://www.wix.com/corvid/forum/community-discussion/sending-template-emails-with-sendgrid-v3
I put in backticks around the variables as suggested by @Roi Bendet as I use them with my non templated email so it seemed logical.

I appreciate any help that you can give me. The sooner the better.
Thank you,
Elizabeth

UPDATE: Hi, I still need help with this. Any help would be wonderful.

did you try like this ?


//-------------Approve Code-------------//
export function sendEmailapprove(recipient, sender, body,
 businessName, member, nonMember, numberOfSpaces) {
  sgMail.setApiKey(apiKey);
 const msg = {
    to: recipient,
    from: 'info@sxxxx.com',
    templateId: 'd-013c14af6fda4a6ea904124e44d61311',
    dynamic_template_data: { businessName, member, nonMember, numberOfSpaces },
  }
  sgMail.send(msg);
}



and in the email it should be {{member}}, …

There might be a chance you are using a legacy transaction template
In that case read this article on how to migrate

If you want to use legacy template you will need to replace the dynamic_template_data => substitutions

I beleive you are using the corrent transactional template version
just send a test email with a hardcode input like this

//-------------Approve Code-------------//
export function sendEmailapprove(recipient, sender, body,
  businessName,member, nonMember, numberOfSpaces) {
  sgMail.setApiKey(apiKey);
 const msg = {
    to: recipient,
    from: 'info@sxxxx.com',
    templateId: 'd-013c14af6fda4a6ea904124e44d61311',
    dynamic_template_data: { member: "This is a test" },
  }
  sgMail.send(msg);
}

@admin51915 I tried both of these. It is still not working.
I can’t do this because this changes every time.
member : “This is a test”

//-------------Approve Code-------------//
export function sendEmailapprove(recipient, sender, body,
  businessName,member, nonMember, numberOfSpaces) {
  sgMail.setApiKey(apiKey);
 const msg = {
    to: recipient,
    from: 'info@sxxxx.com',
    templateId: 'd-013c14af6fda4a6ea904124e44d61311',
    dynamic_template_data: { member: "This is a test" },
  }
  sgMail.send(msg);
}

Also, they are not all members. If you can provide more insight that would help

Any help would be great!

Send me an email at: salmanhammed77@gmail.com