Created
June 30, 2021 18:39
-
-
Save Etheonor/77fc1651c71bb9b9f392185a7b10731a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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