-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreference-center.js
157 lines (144 loc) · 4.38 KB
/
preference-center.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Platform.Load("core", "1.1.2");
var proxy = new Script.Util.WSProxy();
var urlThis = Platform.Request.RequestURL;
var requestType = Request.Method;
var externalKey = "All Subscribers - 265";
var subscriberKey = Variable.GetValue("@subscriberKey") || '[email protected]';
var cols = ["ID", "PartnerKey", "Client.ID", "Client.PartnerClientKey", "EmailAddress", "SubscriberKey", "Status", "EmailTypePreference", "SubscriberList"];
var filter = {
Property: "SubscriberKey",
SimpleOperator: "equals",
Value: subscriberKey
};
var queryAllAccounts = false; // this is important otherwise you just get the parent BU
var deFields = null;
var firstName = '';
var lastName = '';
var email = '';
var unsubscribeFromAllStatus = true;
var emailPreference = "Text";
var subCols = ['ListName', 'ID'];
var subFilter = {
Property: 'ID',
SimpleOperator: 'equals',
Value: 696
};
var publists = null;
try {
//publists = proxy.retrieve('List', subCols, subFilter, queryAllAccounts);
var newSub = {
SubscriberKey: '[email protected]',
EmailAddress: '[email protected]',
Lists: [{
ID: 602,
Status: 'Unsubscribed'
}]
};
var newOptions = {
SaveOptions: [{
PropertyName: '*',
SaveAction: 'UpdateAdd'
}]
};
//var resp = proxy.createItem('Subscriber', newSub, newOptions);
//Write('<br>Response FOR SUB: ' + Stringify(resp));
//Write('<br>IM PUB LIST: ');
// Write(Stringify(publists));
} catch (err) {
Write('<br>Im the error!!!: ');
Write(Stringify(err));
}
if (requestType == "GET") {
if (subscriberKey != "") {
try {
var data = proxy.retrieve("Subscriber", cols, filter, queryAllAccounts);
Write("<br>IM RESULTS");
Write(Stringify(data));
email = data.Results[0].EmailAddress;
firstName = data.Results[0].Attributes[0].Value;
lastName = data.Results[0].Attributes[1].Value;
emailPreference = data.Results[0].EmailTypePreference;
unsubscribeFromAllStatus = data.Results[0].Status == "Unsubscribed" ? "checked" : "";
emailPreference = data.Results[0].EmailTypePreference == "HTML" ? "checked" : "";
} catch (err) {
Write("<br>I Error'd");
Write(Stringify(err));
}
}
} else if (requestType == "POST!!!") {
//Write("<br> IM IN THE POST: ")
//Write(unsubscribeFromAllStatus)
var subscriberKey = Request.GetFormField("subscriberKey");
var firstName = Request.GetFormField("firstName");
var lastName = Request.GetFormField("lastName");
var email = Request.GetFormField("email");
var unsubscribeFromAllStatus = Request.GetFormField("unsubscribe") ? "Unsubscribed" : "Active";
var htmlPreference = Request.GetFormField("preference") ? "HTML" : "Text";
var resp = null;
Write("<br>IM THE VALS UNSUB")
Write(Request.GetFormField("unsubscribe"))
Write("<br>IM THE VALS PREF")
Write(Request.GetFormField("preference"))
if (subscriberKey) {
var sub = {
SubscriberKey: subscriberKey,
EmailAddress: email,
Status: unsubscribeFromAllStatus,
EmailTypePreference: htmlPreference,
Attributes: [{
Name: "First Name",
Value: firstName
},
{
Name: "Last Name",
Value: lastName
},
{
Name: "Email Address",
Value: email
}
]
};
var options = {
SaveOptions: [{
PropertyName: "*",
SaveAction: "UpdateAdd"
}]
};
try {
resp = proxy.updateItem("Subscriber", sub, options);
} catch (err) {
Write("<br>Im the error!!!: ")
Write(Stringify(err))
}
Write("<br>Response!: " + Stringify(resp));
}
}
var subListCols = ["ID"];
var subListfilter = {
Property: "ID",
SimpleOperator: "equals",
Value: 707
};
var newData = null;
try {
newData = proxy.retrieve("ListSubscriber", subListCols, subListfilter, true);
} catch (err) {
Write("<br>IM ERRd")
Write(err)
}
//Write("<br>IM SUBLIST RETRIEVE: ")
//Write(Stringify(newData));
//var val = describeGeneric("AccountUser ");
//Write("<br> IM THE DESCRIBE: ")
//Write(Stringify(val));
var subInit = Subscriber.Init('[email protected]');
var subLists = subInit.Lists.Retrieve();
Write("<br>IM THE SSJS SUB: ")
Write(Stringify(subLists))
//retrieves the name of all retrievable fields inside obj
function describeGeneric(soapObjName) {
//example soapObjName: "DataExtension"
var req = proxy.describe(soapObjName);
return req;
}