Skip to content

Instantly share code, notes, and snippets.

@vishneuski
vishneuski / sendEmail.js
Created February 28, 2024 09:20 — forked from eliotharper/sendEmail.js
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);
@vishneuski
vishneuski / DE Field Search
Created February 21, 2024 12:41 — forked from camrobert/DE Field Search
SSJS script to locate every Field in every Data Extension with a given name
@vishneuski
vishneuski / EncryptSymmetric using DES
Created February 21, 2024 12:41 — forked from camrobert/EncryptSymmetric using DES
AMPscript to Encrypt and Decrypt Symmetric using DES to use with external services
%%[
SET @text = "Cameron Robert"
SET @key = "8ce32e59" /* https://www.browserling.com/tools/random-hex */
OutputLine(Concat("Encrypted: ", EncryptSymmetric(@text, "des;mode=ecb;padding=pkcs7", @null, @key),"<br><br>"))
SET @enctext = "iJwqnvvKdIIn7AKQOg1LHA=="
OutputLine(Concat("Decrypted: ", DecryptSymmetric(@enctext, "des;mode=ecb;padding=pkcs7", @null, @key),"<br><br>"))
]%%
@vishneuski
vishneuski / AMPscript Encrypted Credentials
Created February 21, 2024 12:41 — forked from camrobert/AMPscript Encrypted Credentials
AMPscript to Encrypt & Protect your API Credentials, followed by AMPscript to Decrypt and then use those values in an API call
%%[
/*SET Your 3 Keys*/
SET @sym = 'SymmetricKey ExternalKey'
SET @IV = 'IV ExternalKey'
SET @Salt = 'Salt ExternalKey'
/*Input Auth URI Details*/
SET @authurl = 'Authentication Base URI'
/*TEMP API Key Details - To Delete after generating encrypted values*/
<script runat="server">
Platform.Load("Core", "1");
/* ======================================================= */
/* ======================== Config ======================= */
var authurl = "authmarketingcloudapiscom/"; //Get this from Setup
var client_id = "xxxxxxxxxxxxxxxxx"; //Get this from Setup
var client_secret = "yyyyyyyyyyyyyyy"; //Get this from Setup
var slackwebhook = "zzzzzzzzzzzzzzzzzzzzz"; //Get this from Slack API
var gtm = 10; //This is your GMT modifier for your timezone
var notify = "@channel"; //use this to notify the channel or specific people
<script runat="server">
Platform.Load("Core","1");
try{
var url = 'https://hooks.slack.com/services/xxxxxxxx/yyyyyyyyyyyy/zzzzzzzzzzzzzzzz';
var contentType = 'text/plain';
var payload = '{"text":"Now this is SSJS!"}';
var headerNames = [];
var headerValues = [];
var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
%%[
SET @payload = '{"text":"Hello from SFMC!"}'
SET @post = HTTPPOST2('https://hooks.slack.com/services/xxxxxxxxx/yyyyyyyyyyyy/zzzzzzzzzzzzzzz','text/plain',@payload,true,@output,@header)
]%%
@post= %%=v(@post)=%% <br>
@output= %%=v(@output)=%% <br>
@header= %%=v(@header)=%% <br>
@vishneuski
vishneuski / SSJS Get all Users
Created February 21, 2024 12:38 — forked from camrobert/SSJS Get all Users
SSJS and WSProxy code to return all valid users in a Marketing Cloud instance
<script runat="server">
/*Code provided as is without warranty - make sure you understand what this code does before using it - use at your own risk*/
Platform.Load("Core","1");
try {
var prox = new Script.Util.WSProxy();
//================== https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/accountuser.html
var cols = ["Name","CustomerKey","NotificationEmailAddress", "UserID", "ActiveFlag", "Email", "IsAPIUser", "AccountUserID", "LastSuccessfulLogin", "CreatedDate", "Roles"];
//================= https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_WSProxy_basic_retrieve.html
var filter = {
LeftOperand: {Property: "Email",SimpleOperator: "like",Value: "@"},
<script runat="server">
/*
Ref: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_httpPost.html
Ref: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/validateEmail.html
*/
Platform.Load("Core","1");
try {
/*=== (unsafe) Plain Text API Credentials ===*/
var authurl = "https://mcxxxxxxxxxxxxxxxx.auth.marketingcloudapis.com/";
<script runat="server">
Platform.Load("Core","1");
try {
var prox = new Script.Util.WSProxy();
var cols = ["Name","CustomerKey","CategoryID"];
var filter = {Property: "Name",SimpleOperator: "equals",Value: "Cam DE"};
var res = prox.retrieve("DataExtension",cols,filter);
//Write('Message: '+ Stringify(res));
for (s = 0; s < res.Results.length; s++) {