Error when sending template emails with SendGrid v3

Hi,

I have been successfully sending transactional emails on form submission but I would now like to add a template (set up in SendGrid)

I have followed the steps in this post https://www.wix.com/code/home/forum/community-discussion/sending-template-emails-with-sendgrid-v3 to upgrade to V3 but I am receiving an error on form submission…

Unhandled promise rejection TypeError: (0 , _sendGrid.sendInstruction) is not a function

Is anyone able to help me? Here is my code…

//email.jsw

import {sendInstruction} from 'backend/sendGrid';

export function sendMarketingEmail(subject, body, recipient) { 
const key = "xxxxxxxxxxYourAPIKeyHerexxxxxxx"; 
const sender = "senderEmailAddress"; 
return sendInstruction(key, sender, recipient, subject, body);
}

//sendgrid.js

import { fetch } from 'wix-fetch';

export function SendInstruction(key, sender, recipient, subject, body) {
 const url = "https://api.sendgrid.com/v3/mail/send";

 const MyHeaders = {
 "Authorization": "Bearer " + key,
 "Content-Type": "application/json"
    };
 const MyBody = {
 "personalizations": [{
 "to": [{
 "email": recipient
            }]
        }],
 "from": {
 "email": sender
        },
 "subject": subject,
 "content": [{
 "type": "text/html",
 "value": body
        }],
 "template_id": "d-756b8513f89748ae94640cc7691e80f0"
    };

 return fetch(url, {
 "method": "POST",
 "headers": MyHeaders,
 "body": JSON.stringify(MyBody)
        })
        .then(Response => Response.text);
}

Page Code

import { sendMarketingEmail } from 'backend/email';

function sendToRecipient() {

 const recipient = $w("#inputRecipientEmail").value;
    sendMarketingEmail(recipient)
        .then(response => console.log(response));
}

Your import statement is incorrect. Seems like you mean this instead:

import {SendInstruction} from 'backend/sendGrid';

SendInstruction instead of sendInstruction (capital S)

Thank you, Yisrael. I checked the spelling a hundred times but still missed the capital letter!

@rachelskuse I know all too well how it is. :upside_down_face: