Skip to content

Instantly share code, notes, and snippets.

@camrobert
camrobert / Dad_Joke_CloudPage_SSJS.js
Created November 15, 2021 10:15
Dad Joke CloudPage SSJS code for Slack API Integration
/*
=======================================================
Title: Dad Joke CloudPage SSJS code for Slack API Integration.
Author: Cameron Robert
-------------------------------------------------------
Instructions:
1: Create a Javascript Code Resource CloudPage
2: Paste the below code to the page
3: Use the Cloud Page URL as "Request URL" for a "Slash Commands" component in the Slack API Dashboard.
4: Save and Authorise your Slack app to a workspace/channel, and use the Slash Command to interact
@camrobert
camrobert / DE_Count_Slack_API.sj
Created November 15, 2021 10:18
SFMC DE Record Count Slack API
/*
=======================================================
Title: SFMC DE Record Count Slack API
Author: Cameron Robert
-------------------------------------------------------
Instructions:
1: Create a Javascript Code Resource CloudPage
2: Paste the below code to the page
3: Use the Cloud Page URL as "Request URL" for a "Slash Commands" component in the Slack API Dashboard.
4: Save and Authorise your Slack app to a workspace/channel.
%%[
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>
<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);
<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
@camrobert
camrobert / EncryptSymmetric using DES
Last active February 21, 2024 12:41
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>"))
]%%
@camrobert
camrobert / AMPscript Encrypted Credentials
Created July 3, 2022 22:57
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*/
@camrobert
camrobert / DE Field Search
Last active February 21, 2024 12:41
SSJS script to locate every Field in every Data Extension with a given name
@camrobert
camrobert / SSJS Get all Users
Created December 2, 2022 12:45
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: "@"},