Resend API not sending JSON response
Unanswered
Transvaal lion posted this in #help-forum
Transvaal lionOP
I am using the API [resend](https://resend.com/overview) to connect a form sent from NextJS, but is not able to send the response due to this error:
This error appears under the
This is the entire backend file:
Argument of type 'CreateEmailResponse' is not assignable to parameter of type 'Data'.Property 'name' is missing in type 'CreateEmailResponse' but required in type 'Data'.ts(2345)sendEmail.ts(8, 5): 'name' is declared here.This error appears under the
POST method, when I try to send a response with email.res.status(200).json(email)This is the entire backend file:
type Data = {
name: string,
message?: string,
}
const KEY = process.env.PORTFOLIO_KEY
const TO = process.env.EMAIL_TO
const resend = new Resend(KEY)
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
try{
switch(req.method){
case 'POST':
//code
const email = await resend.emails.send({
from: 'Acme <onboarding@resend.dev>',
to: [`${TO}`],
subject: 'Hello world',
react: EmailTemplate({ firstName: 'John' }),
});
res.status(200).json(email) //error here
break;
}
}
catch(e ){
if(typeof e === "string")
res.status(400).json({name: "Bad", message: e.toUpperCase()})
if(e instanceof Error)
res.status(400).json({ name: "Bad", message: e.message})
}
}2 Replies
Transvaal lionOP
Email template
import React from 'react';
export default function EmailTemplate(props: any) {
const { firstName, product } = props;
return (
<div>
<h1>Welcome, {firstName}!</h1>
<p>Thanks for trying {product}. We’re thrilled to have you on board.</p>
</div>
);
}Transvaal lionOP
I added the
but I don't like adding
any to the variable and it fixed the issue.const email : any = await resend.emails.send({but I don't like adding
any as a type, what would be a more accurate type?