Skip to content

Instantly share code, notes, and snippets.

Avatar

Eliot Harper eliotharper

View GitHub Profile
@eliotharper
eliotharper / controller.js
Last active Nov 28, 2021
Sample SSJS used in a CloudPage Code Resource to track engagement of AMP Emails
View controller.js
<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 Feb 22, 2021
SSJS controller example for AMP email sent from SFMC
View sfmcdg-amp-controller.js
<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'
View sfmcdg-amp-email.html
<!-- {{={< >}=}} -->
<!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 Jan 31, 2021
Updates SFMC Query Activity with Auto-Suppression list as target Data Extension
View UpdateQuery.js
<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 Oct 12, 2020
SSJS Script to delete Contacts from Salesforce Marketing Cloud
View deleteContacts.js
<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 Sep 15, 2020
WSProxy example for SSJS and SFMC to send triggered send email
View sendEmail.js
<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 Sep 15, 2020
Example SSJS for SFMC that retrieves weather forecast from an external API
View getWeather.js
<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 Sep 15, 2020
Creates a backup Data Extension in SFMC
View copyDE.js
<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 Apr 29, 2018
SOAP API method to update existing Subscriber in Salesforce Marketing Cloud
View updateSubscriber.xml
<!--
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>
View payload.json
{
"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": [