Skip to content

Instantly share code, notes, and snippets.

View eliotharper's full-sized avatar

Eliot Harper eliotharper

View GitHub Profile
@eliotharper
eliotharper / controller.js
Last active February 28, 2024 09:23
Sample SSJS used in a CloudPage Code Resource to track engagement of AMP Emails
<script language='javascript' runat='server'>
Platform.Load('Core', '1');
// Arrays of allowed values for both Sender Address and Sender Origin
// Sender Address is the from address when you send an email, make sure your expected from address is included in the list
// Sender Origin represents the domain originating the request
// The Marketing Cloud origin is in place to allow testing in Subscriber Preview, update that value to match your stack
var isAllowed = {
senderAddress:[
'amp@gmail.dev' // add 'from' addresses here
@eliotharper
eliotharper / sfmcdg-amp-controller.js
Created February 22, 2021 01:06
SSJS controller example for AMP email sent from SFMC
<script language='javascript' runat='server'>
Platform.Load('Core', '1');
// Arrays of allowed values for both Sender Address and Sender Origin
// Sender Address is the from address when you send an email, make sure your expected from address is included in the list
// Sender Origin represents the domain originating the request
// The Marketing Cloud origin is in place to allow testing in Subscriber Preview, update that value to match your stack
var isAllowed = {
senderAddress:[
'amp@gmail.dev'
@eliotharper
eliotharper / sfmcdg-amp-email.html
Created February 22, 2021 01:03
Sample AMP email
<!-- {{={< >}=}} -->
<!doctype html>
<html ⚡4email data-css-strict>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
@eliotharper
eliotharper / UpdateQuery.js
Created January 31, 2021 09:48
Updates SFMC Query Activity with Auto-Suppression list as target Data Extension
<script language="javascript" runat="server">
// Author: Eliot Harper <eliot@eliot.com.au>
// Revision date: January 31, 2021
// DISCLAIMER
// While due care has been taken in the preparation of this
// supplied code example, no liability is assumed for incidental
// or consequential damages in connection with or arising out its
// use. Example code is provided on an "as is" basis and no
// expressed or implied warranty of any kind is made for the
@eliotharper
eliotharper / deleteContacts.js
Created October 12, 2020 05:07
SSJS Script to delete Contacts from Salesforce Marketing Cloud
<script language="javascript" runat="server">
Platform.Load("core","1.1.5");
// Author: Eliot Harper <eliot@eliot.com.au>
// Revision date: October 24, 2019
// DISCLAIMER
// While due care has been taken in the preparation of this
// supplied code example, no liability is assumed for incidental
// or consequential damages in connection with or arising out its
@eliotharper
eliotharper / sendEmail.js
Created September 15, 2020 23:40
WSProxy example for SSJS and SFMC to send triggered send email
<script runat=server>
var city = Platform.Request.GetFormField('city');
var email = Platform.Request.GetFormField('email');
// Detect form submission
if ( (city) && (email) ) {
var weather = getWeather(city);
@eliotharper
eliotharper / getWeather.js
Created September 15, 2020 23:39
Example SSJS for SFMC that retrieves weather forecast from an external API
<script runat=server>
var apiKey = 'INSERT_WEATHERSTACK_API_KEY_HERE';
var city = Platform.Request.GetQueryStringParameter('city');
if (city) {
var url = 'http://api.weatherstack.com/forecast?access_key=' + apiKey + '&query=' + city;
var weather = Platform.Function.HTTPGet(url);
@eliotharper
eliotharper / copyDE.js
Created September 15, 2020 23:37
Creates a backup Data Extension in SFMC
<script runat=server>
Platform.Load("core", "1");
// create DE
var timeStamp = Math.round((new Date()).getTime() / 1000);
var deKey = "BACKUP_" + timeStamp;
var deName = "Backup DE " + timeStamp;
var obj = {
@eliotharper
eliotharper / updateSubscriber.xml
Created April 29, 2018 23:58
SOAP API method to update existing Subscriber in Salesforce Marketing Cloud
<!--
Use the following cURL command to execute this request:
curl -XPOST -H "Content-type: text/xml; charset=utf-8" -H "SOAPAction: Update" -d @request.xml https://webservice.s7.exacttarget.com/Service.asmx
Replace 's7' with your SOAP endpoint as required
-->
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<fueloauth xmlns="http://exacttarget.com">insertAccessTokenHere</fueloauth>
{
"ref": "refs/heads/master",
"before": "c590fa60a37627f6d07fc74cfb44758752963e7a",
"after": "4a372650814b0c191dc10064830e5e4e5cbf3130",
"created": false,
"deleted": false,
"forced": false,
"base_ref": null,
"compare": "https://github.com/eliotharper/ampscript-guide-build/compare/c590fa60a376...4a372650814b",
"commits": [