Created
December 30, 2023 06:34
-
-
Save theindianappguy/5de570b9a8360c9a2097ab87838f4dbc to your computer and use it in GitHub Desktop.
GoogleSheets-MailerLite-Integration-Automated-Email-Script
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
function doPost(request) { | |
// Open Google Sheet using ID | |
var sheet = SpreadsheetApp.openById("SHEETID"); | |
var result = { "status": "SUCCESS" }; | |
// try { | |
// Get all Parameters | |
var email = request.parameter.email || ""; | |
var source = request?.parameter.source ?? ""; | |
var today = new Date(); | |
var dd = String(today.getDate()).padStart(2, '0'); | |
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! | |
var yyyy = today.getFullYear(); | |
var todayString = mm + '/' + dd + '/' + yyyy; | |
Logger.log(todayString) | |
// Append data on Google Sheet | |
var rowData = sheet.appendRow([email, source, todayString, today.toString()]); | |
// add user to the onboarding emails -------------------------------------------------- | |
// Add to Maillerlite Group | |
var newCustomerMagicSlidesGroupID = "GROUP_ID"; | |
var apiKeyMagicSlides = "API_KEY"; | |
addEmailtoMailerlite({ | |
email: email, | |
apiKey: apiKeyMagicSlides, | |
groupId: newCustomerMagicSlidesGroupID, | |
}); | |
// ----------------- end -------------------------------------------------- | |
// } catch (exc) { | |
// If error occurs, throw exception | |
// result = { "status": "FAILED", "message": exc }; | |
// } | |
// Return result | |
return ContentService | |
.createTextOutput(JSON.stringify(result)) | |
.setMimeType(ContentService.MimeType.JSON); | |
} | |
async function addEmailtoMailerlite({ email, apiKey, groupId }) { | |
Logger.log("email " + email + " apiKey " + apiKey + " groupId " + groupId) | |
// try { | |
var url = | |
"https://add-email-to-mailerlite.vercel.app/addmail" + | |
`?email=${email}` + | |
`&groupId=${groupId}` + | |
`&apiKey=${apiKey}`; | |
Logger.log(url + "url") | |
var response = await UrlFetchApp.fetch(url, { muteHttpExceptions: true }); | |
Logger.log(response); | |
// } catch (error) { | |
// Logger.log(`Error in addEmailtoMailerlite: ${error}`); | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
` const [visitorEmail, setvisitorEmail] = useState("");
const [pushingEmail, setpushingEmail] = useState(false);
function pushEmails(e: any) {
e.preventDefault()
setpushingEmail(true)
console.log(
visitorEmail: ${visitorEmail}
);// check if validated email if not return
if (!ValidateEmail(visitorEmail)) {
showSnackbar("Email not valid");
setpushingEmail(false)
return;
}
console.log(
document.referrer: ${document.referrer}
);var myHeaders = new Headers();
myHeaders.append(
"Cookie",
"S=maestro=3x22VQghgpKcECF_GKqtuRrqh5gSi9LKkBjykWc4WGw"
);