Skip to content

Instantly share code, notes, and snippets.

View eliotharper's full-sized avatar

Eliot Harper eliotharper

View GitHub Profile
@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 / 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 / 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 <[email protected]>
// 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 / 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 <[email protected]>
// 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 / 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 / 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 / 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:[
'[email protected]' // add 'from' addresses here
@eliotharper
eliotharper / configuration.yaml
Created June 4, 2025 20:19
Home Assistant YAML configuration for Selectronic Inverter
sensor:
- platform: rest
name: "selectronic"
json_attributes_path: "$.items"
json_attributes:
- "battery_in_wh_today"
- "battery_in_wh_total"
- "battery_out_wh_today"
- "battery_out_wh_total"
- "battery_soc"