Skip to content

Instantly share code, notes, and snippets.

@Etheonor
Created June 30, 2021 18:39
Show Gist options
  • Save Etheonor/77fc1651c71bb9b9f392185a7b10731a to your computer and use it in GitHub Desktop.
Save Etheonor/77fc1651c71bb9b9f392185a7b10731a to your computer and use it in GitHub Desktop.
import axios from "axios";
export default async function handler(req, res) {
if (req.method === "PUT") {
axios
.put(
"https://api.sendgrid.com/v3/marketing/contacts",
{
contacts: [{ email: `${req.body.mail}` }],
list_ids: [process.env.SENDGRID_MAILING_ID],
},
{
headers: {
"content-type": "application/json",
Authorization: `Bearer ${process.env.SENDGRID_SECRET}`,
},
}
)
.then((result) => {
res.status(200).send({
message:
"Your email has been succesfully added to the mailing list. Welcome 👋",
});
})
.catch((err) => {
res.status(500).send({
message:
"Oups, there was a problem with your subscription, please try again or contact us",
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment