Skip to content

Instantly share code, notes, and snippets.

@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:[
'[email protected]'
@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>
@jdeblank
jdeblank / ssjs_wsproxy_updatePublist.js
Last active January 22, 2023 01:03
Use SSJS and WSProxy to add/update a subscriber status in Publication List within Salesforce Marketing Cloud
<script runat="server">
Platform.Load("core","1.1.1");
var subkey = "abc123";
var email = "[email protected]"
var prox = new Script.Util.WSProxy();
// Set specific BU context if required
// prox.setClientId({ "ID": 7279411 });
<script runat="server">
Platform.Load("core","1.1.1");
// Example of HTTP GET/POST to SFMC REST API to retrieve HTML of an email
try {
var authBaseUrl = 'https://abcd.auth.marketingcloudapis.com';
var authEndPoint = '/v1/requestToken';
var restBaseUrl = 'https://abcd.rest.marketingcloudapis.com';
<script runat="server">
Platform.Load("core","1.1.1");
/*
Example that handles JSON data POSTed to this page.
e.g '{"firstname":"Joe","lastname":"Bloggs"}'
*/
var jsonpost, jsondata;
<script runat="server">
var prox = new Script.Util.WSProxy();
var tsdKey = '123';
var EmailAddress = '[email protected]';
var tsd = {
TriggeredSendDefinition: {
CustomerKey: tsdKey
<script runat="server">
Platform.Load("core","1.1.1");
var prox = new Script.Util.WSProxy();
// Need to retrieve the ObjectID for the Automation, which isn't available via the SFMC interface.
var cols = ["Name", "ProgramID", "IsActive"];
var filter = {
Property: "Name",
SimpleOperator: "equals",
<script runat="server">
Platform.Load("core","1.1.1");
var listid = 1234;
var jobid = 567;
var batchid = 1;
var mids = {
BU1: 123456,
BU2: 123457,
<script runat="server">
var skey = "abc123";
var prox = new Script.Util.WSProxy();
// query all BUs
var queryAllAccounts = true;
// set the attributes to be retrieved
// note Client.ID and not ClientID
var cols = ["Status","Client.ID"];
<script runat="server">
Platform.Load("core","1.1.1");
try {
var de = DataExtension.Init('DE Name goes here');
var data = {
id: Request.GetFormField("id"),
FirstName: Request.GetFormField("firstname"),
Email: Request.GetFormField("email")
}