The Salesforce Marketing Cloud (SFMC) REST API is a web-based interface that allows developers to programmatically interact with the SFMC platform. It offers capabilities for managing subscribers, sending emails, creating and managing data extensions, setting up marketing automation, accessing reporting and tracking data, and customizing integrations, making it a versatile tool for automating and extending marketing campaigns within SFMC.
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Get the 'memberid' attribute from the recipient
var MemberID = Platform.Recipient.GetAttributeValue('memberid');
// Retrieve client credentials from a configuration source
var ClientId = get_config[0]["Client_ID"];
var ClientSecret = get_config[0]["Client_Secret"];
// Define the URL for the token endpoint
var url = 'domain/v2/token';
// Set the Content-Type for the HTTP request
var ContentType = 'application/json';
// Create a JSON payload for the request to obtain an access token
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to the token endpoint
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
// Retrieve the HTTP response status code
var statusCode = accessTokenResult["StatusCode"];
// Extract the response content from the HTTP request
var response = accessTokenResult["Response"][0];
// Parse the JSON response to extract the access token
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
} catch (e) {
// Handle any errors that may occur during the execution of the script
Write(e.message);
}
</script>
Write AMPscript code block to retrieve Access Token via AUTH API
//Example1
%%[
VAR @httppost,@Eventkey, @EventName, @EventDate, @Is_Email_Sent,@FirstName
VAR @emailValue, @subscriberKeyValue
VAR @rows, @row, @rowCount
VAR @body, @callstatus, @response, @Client_ID, @Client_Secret, @Email_Settings,@postrequest
SET @url = 'https://{{et_subdomain}}.auth.marketingcloudapis.com/v2/token/'
SET @body = Concat('{"client_id": "',@Client_ID,'", "client_secret": "',
@Client_Secret,'","grant_type": "client_credentials"}')
SET @httppost = HTTPPost2(@url, "application/json; charset=utf-8", @body, false,
@callstatus, @response)
]%%
//Example2
%%[
/* Define variables*/
VAR @httppost,@url
VAR @body, @callstatus, @response, @Client_ID, @Client_Secret
/* assign variables*/
SET @url = 'https://tenantendpoint.auth.marketingcloudapis.com/v2/Token'
SET @Client_ID='xxxxxxxxxxxxx'
SET @Client_Secret='XXXXXXXXXXXXXXXXXX'
/* define the payload*/
SET @body = Concat('{"client_id": "',@Client_ID,'", "client_secret": "',@Client_Secret,'","grant_type": "client_credentials"}')
/* Invoke HTTPPOST */
SET @httppost = HTTPPost2(@url, "application/json; charset=utf-8", @body, false,@callstatus, @response)
]%%
Platform.Load("core", "1");
//Get the @response variable from AMPscript
var response = Variable.GetValue("@callstatus");
// Parse the JSON and get the access token
var obj = Platform.Function.ParseJSON(response);
var val = obj.access_token;
//Set the Variable to be accessible in AMPscript
Variable.SetValue("@access_token",val);
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for the email validation API
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/address/v1/validateEmail';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for the email validation request
var payload = {
"email": "help@example.com",
"validators": ["SyntaxValidator", "MXValidator", "ListDetectiveValidator"]
};
// Send an HTTP POST request to the email validation API
var authResponse = HTTP.Post(setupURL, ContentType, Stringify(payload), headerNames, headerValues);
var statusCode = authResponse["StatusCode"];
var response = authResponse["Response"][0];
// Display the response from the email validation API
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating or updating a contact
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/contacts/v1/contacts';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for creating or updating a contact
var payload = {
"contactKey": "demo1", // Replace with the contact key
"attributeSets": [{
"name": "Email Addresses",
"items": [{
"values": [{
"name": "Email Address",
"value": "shashi.prasad@salesforce.com"
},
{
"name": "HTML Enabled",
"value": true
}]
}]
},
{
"name": "Email Demographics",
"items": [{
"values": [
{
"name": "First Name",
"value": "Shashi"
}]
}]
}]
};
// Send an HTTP POST request to create or update the contact
var authResponse = HTTP.Post(setupURL, ContentType, Stringify(payload), headerNames, headerValues);
var statusCode = authResponse["StatusCode"];
var response = authResponse["Response"][0];
// Display the response from the contact creation or update
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for obtaining user information
var setupURL = 'https://DOMAIN.auth.marketingcloudapis.com/v2/userinfo';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Send an HTTP GET request to obtain user information
var authResponse = HTTP.Get(setupURL, headerNames, headerValues);
var statusCode = authResponse["Status"];
var response = authResponse["Content"][0];
// Display the response from the UserInfo API
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for obtaining content categories
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/asset/v1/content/categories';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Send an HTTP GET request to obtain content categories
var authResponse = HTTP.Get(setupURL, headerNames, headerValues);
var statusCode = authResponse["Status"];
var response = authResponse["Content"][0];
// Display the response from the Asset API
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating or updating a row in a data extension
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/hub/v1/dataevents/key:{DE_External_Key}/rowset';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for creating or updating a row in the data extension
var payload = [
{
"keys": {
"subscriberKey": "b2.shashi@gmail.com"
},
"values": {
"FirstName": "Sasee",
"LastName": "Prasad",
"Email": "b2.shashi@gmail.com"
}
}
];
// Send an HTTP POST request to create or update the row in the data extension
var authResponse = HTTP.Post(setupURL, ContentType, Stringify(payload), headerNames, headerValues);
var statusCode = authResponse["StatusCode"];
var response = authResponse["Response"][0];
// Display the response from the row creation or update
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating or updating rows in a data extension asynchronously
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/data/v1/async/dataextensions/key:{DE_External_Key}/rowset';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for creating or updating rows in the data extension
var payload = {
"items": [
{
"SubscriberKey": "b2.shashi@gmail.com",
"FirstName": "Sasee",
"LastName": "Prasad",
"Email": "b2.shashi@gmail.com"
},
{
"SubscriberKey": "shashi@gmail.com",
"FirstName": "Sasee",
"LastName": "Prasad",
"Email": "b2.shashi@gmail.com"
}
]
};
// Send an HTTP POST request to create or update the rows in the data extension asynchronously
var authResponse = HTTP.Post(setupURL, ContentType, Stringify(payload), headerNames, headerValues);
var statusCode = authResponse["StatusCode"];
var response = authResponse["Response"][0];
// Display the response from the row creation or update
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating or updating a row in a data extension asynchronously
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/hub/v1/dataeventsasync/key:{DE_External_Key}/rowset';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for creating or updating a row in the data extension asynchronously
var payload = [
{
"keys": {
"subscriberKey": "b2.shashi@gmail.com"
},
"values": {
"FirstName": "Sasee",
"LastName": "Prasad",
"Email": "b2.shashi@gmail.com"
}
}
];
// Send an HTTP POST request to create or update the row in the data extension asynchronously
var authResponse = HTTP.Post(setupURL, ContentType, Stringify(payload), headerNames, headerValues);
var statusCode = authResponse["StatusCode"];
var response = authResponse["Response"][0];
// Display the response from the row creation or update
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating or updating a contact
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/contacts/v1/contacts';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for creating or updating a contact
var payload = {
"contactKey": "Shashi1",
"attributeSets": [
{
"name": "Email Addresses",
"items": [
{
"values": [
{
"name": "Email Address",
"value": "b2.shashi+updated1@gmail.com"
},
{
"name": "HTML Enabled",
"value": true
}
]
}
]
},
{
"name": "Email Demographics",
"items": [
{
"values": [
{
"name": "First Name",
"value": "Sasee"
}
]
}
]
}
]
};
// Create an HTTP request object
var request = new Script.Util.HttpRequest(setupURL);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", accesstoken); // Fixed a typo in "accesstokenn"
request.method = "PATCH"; // Use the PATCH method for updates
request.contentType = "application/json; charset=utf-8";
request.postData = Stringify(payload);
// Send the HTTP request and receive the response
var httpResponse = request.send();
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response from the contact creation or update
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for searching email addresses
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/contacts/v1/addresses/email/search';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for searching email addresses
var payload = {
"ChannelAddressList": ["b2.shashi+updated@gmail.com"],
"MaximumCount": 5
};
// Send an HTTP POST request to search for email addresses
var httpResponse = HTTP.Post(setupURL, "application/json", Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response from the email address search
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for deleting contacts by their keys
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/contacts/v1/contacts/actions/delete?type=keys';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for deleting contacts by their keys
var payload = {
"values": [193969589, 183112375],
"DeleteOperationType": "ContactAndAttributes"
};
// Send an HTTP POST request to delete contacts by their keys
var httpResponse = HTTP.Post(setupURL, "application/json", Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response from the contact deletion
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for deleting contact analytics delete requests
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/contacts/v1/contacts/analytics/deleterequests';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Send an HTTP GET request to delete contact analytics delete requests
var httpResponse = HTTP.GET(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Status"];
var response = httpResponse["Content"][0];
// Display the response from the contact analytics delete requests deletion
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for retrieving summary information about contact analytics delete requests
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/contacts/v1/contacts/analytics/deleterequests/summary';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.GET(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Status"];
var response = httpResponse["Content"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for retrieving summary information about interactions
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/interaction/v1/interactions';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.GET(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Status"];
var response = httpResponse["Content"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
function GetCategoryIDForJourney() {
var filter1 = {
Property: "Name",
SimpleOperator: "equals",
Value: "Shashi"
};
var filter2 = {
Property: "ContentType",
SimpleOperator: "equals",
Value: "journey"
};
var complexFilter = {
LeftOperand: filter1,
LogicalOperator: "AND",
RightOperand: filter2
};
var results = Folder.Retrieve(complexFilter);
return results[0].ID;
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating an interaction (journey)
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/interaction/v1/interactions';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
var contentType = "application/json;charset=UTF-8";
var payload = {
"key": "journey-created-via-the-api-shashi",
"name": "API-Created journey version-1",
"workflowApiVersion": 1,
"categoryId": GetCategoryIDForJourney(),
"triggers": [],
"goals": [],
"activities": []
};
// Send an HTTP POST request to create the interaction (journey)
var httpResponse = HTTP.POST(setupURL, contentType, Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
function GetCategoryIDForJourney() {
var filter1 = {
Property: "Name",
SimpleOperator: "equals",
Value: "Shashi"
};
var filter2 = {
Property: "ContentType",
SimpleOperator: "equals",
Value: "journey"
};
var complexFilter = {
LeftOperand: filter1,
LogicalOperator: "AND",
RightOperand: filter2
};
var results = Folder.Retrieve(complexFilter);
return results[0].ID;
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating an interaction (journey)
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/interaction/v1/interactions';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
var contentType = "application/json;charset=UTF-8";
var payload={
"key": "Basic Journey Reverse Engineering",
"name": "Basic Journey Reverse Engineering",
"description": "We are using this journey to learn how to use the Journey Spec in Journey Builder",
"categoryId":GetCategoryIDForJourney(),
"workflowApiVersion": 1,
"triggers": [
{
"key": "event-key",
"name": "Starting point for the journey",
"type": "APIEvent",
"eventDefinitionKey": "APIEvent-c204d5ab-543c-56de-f7f2-75c2f9220411",
"arguments": {},
"configurationArguments": {}
}
]
}
// Send an HTTP POST request to create the interaction (journey)
var httpResponse = HTTP.POST(setupURL, contentType, Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
function GetJourneyPayload(journeyKey,journeyName,description)
{
var jb_payload={
"key": journeyKey,
"name": journeyName,
"description":description,
"entryMode": "MultipleEntries",
"categoryId":GetCategoryIDForJourney(),
"workflowApiVersion": 1,
"triggers": [
{
"key": "TRIGGER",
"name": "api-event",
"description": "",
"type": "APIEvent",
"outcomes": [],
"arguments": {},
"configurationArguments": {
"criteria": ""
}
}
],
"goals": [],
"activities": [
{
"key": "postman-email-key-1",
"name": "Welcome Email",
"description": "",
"type": "EMAILV2",
"outcomes": [
{
"key": "sent-email-now-wait",
"next": "welcome-email-then-wait",
"arguments": {},
"metaData": {}
}
],
"arguments": {},
"configurationArguments": {
"applicationExtensionKey": "jb-email-activity",
"triggeredSend": {
"emailId": 287896,
"emailSubject": "Hello World!",
"name": "TransactionalAPI",
"isSalesforceTracking": true,
"isMultipart": true,
"isSendLogging": true,
"suppressTracking": false,
"isTrackingClicks": true
}
},
"metaData": {
"isConfigured": true
}
},
{
"key": "welcome-email-then-wait",
"name": "1 minute",
"type": "WAIT",
"configurationArguments": {
"waitDuration": 1,
"waitUnit": "MINUTES"
},
"metaData": {
"isConfigured": true,
"waitType": "duration"
}
}
]
}
return jb_payload;
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for creating an interaction (journey)
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/interaction/v1/interactions';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
var contentType = "application/json;charset=UTF-8";
var journeyKey="SSJS-Created journey version1";
var journeyName="SSJS-Created journey version1";
var description="SSJS-Created journey version1";
var payload=GetJourneyPayload(journeyKey,journeyName,description);
// Send an HTTP POST request to create the interaction (journey)
var httpResponse = HTTP.POST(setupURL, contentType, Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accessToken = 'Bearer ' + getAccessToken();
// Replace 'definitionId' with the actual ID you want to retrieve
var definitionId = 'your-definition-id';
// Define the URL for retrieving summary information about an interaction (journey)
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/interaction/v1/interactions/' + definitionId + '/summary';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accessToken];
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.Get(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Statu"];
var response = httpResponse["Content"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accessToken = 'Bearer ' + getAccessToken();
// Replace 'definitionId' with the actual ID you want to retrieve
var definitionId = 'your-definition-id';
// Define the URL for retrieving summary information about an interaction (journey)
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/interaction/v1/waitstatistics/' + definitionId;
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accessToken];
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.Get(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Status"];
var response = httpResponse["Content"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
function GetCategoryIDForJourney()
{
var filter1={
Property:"Name",SimpleOperator:"equals",Value:"Shashi"};
var filter2={
Property:"ContentType",SimpleOperator:"equals",Value:"journey"};
var complexFilter = {
LeftOperand: filter1,LogicalOperator: "AND",RightOperand: filter2};
var results = Folder.Retrieve(complexFilter);
return results[0].ID;
}
function GetTriggersAsDataExtension(guid)
{
return [
{
"key": "TRIGGER",
"name": "TRIGGER",
"description": "",
"type": "EmailAudience",
"outcomes": [],
"arguments": {},
"configurationArguments": {},
"metaData": {
"eventDefinitionId": guid,
"eventDefinitionKey":"DEAudience-58c59b6f-63fd-cb52-206b-1ade3d2a0742",
"chainType": "None",
"configurationRequired": false,
"iconUrl": "/images/icon-data-extension.svg",
"title": "Data Extension",
"entrySourceGroupConfigUrl": "jb:///data/entry/audience/entrysourcegroupconfig.json",
"sourceInteractionId": "00000000-0000-0000-0000-000000000000"
}
}
];
}
function GetTriggersAsAPIEvent()
{
return [
{
"key": "TRIGGER",
"name": "TRIGGER",
"description": "",
"type": "APIEvent",
"outcomes": [],
"arguments": {},
"configurationArguments": {},
"metaData": {
"eventDefinitionId": "8f35a92e-81c4-44ab-99d7-1ea10428a944",
"eventDefinitionKey": "APIEvent-c026f9d0-c015-764e-f77e-c14e48508952",
"chainType": "None",
"configurationRequired": false,
"iconUrl": "/images/icon_journeyBuilder-event-api-blue.svg",
"title": "",
"entrySourceGroupConfigUrl": "jb:///data/entry/api-event/entrysourcegroupconfig.json",
"sourceInteractionId": "00000000-0000-0000-0000-000000000000"
}
}
];
}
function GetTriggersAsContactEvent()
{
return [
{
"key ": "TRIGGER ",
"name ": "TRIGGER",
"description ": " ",
"type ": "ContactEvent ",
"outcomes ": [],
"arguments ": {
"serializedObjectType ": 2,
"eventDefinitionId ": "859a2224-da91-483f-a65e-95b1e6498c1f ",
"eventDefinitionKey ": "ContactEvent-be00796b-d9a5-504f-6ddc-e33772af81df ",
"dataExtensionId ": "6e7b20b6-4918-ee11-b853-48df37deb2a2 "
},
"configurationArguments ": {},
"metaData ": {
"scheduleState ": "No Schedule ",
"eventDefinitionId ": "859a2224-da91-483f-a65e-95b1e6498c1f ",
"eventDefinitionKey ": "ContactEvent-be00796b-d9a5-504f-6ddc-e33772af81df ",
"chainType ": "None ",
"configurationRequired ": false,
"iconUrl ": "/images/icon_journeyBuilder-event-person-blue.svg ",
"title ": " ",
"category ": "Event ",
"entrySourceGroupConfigUrl ": "jb:///data/entry/event/entrysourcegroupconfig.json ",
"sourceInteractionId ": "00000000-0000-0000-0000-000000000000 "
}
}
];
}
function GetTriggersAsGA()
{
return [
{
"key ": "TRIGGER ",
"name ": "TRIGGER",
"description ": " ",
"type ": "EmailAudience ",
"outcomes ": [],
"arguments ": {},
"configurationArguments ": {
"applicationExtensionKey ": "4dfa951d-7727-4a93-b176-4e0444c61b34 ",
"criteria ": " "
},
"metaData ": {
"icon ": "https://external-audience-selector.s10.marketingcloudapps.com/ga360/ga360-logo.svg ",
"iconSmall ": "https://external-audience-selector.s10.marketingcloudapps.com/ga360/ga360-logo.svg ",
"isConfigured ": true,
"audienceType ": "GA360 ",
"statsContactIcon ": null,
"original_iconSmall ": "ga360-logo.svg ",
"original_icon ": "ga360-logo.svg ",
"audienceId ": 55,
"audienceName ": "All Users ",
"audienceCount ": 0,
"eventDefinitionId ": "501310f7-9692-46fc-bc0b-89bc36e9837f ",
"eventDefinitionKey ": "DEAudience-1e69bf04-b68f-80ec-02f5-761d0c06f2c7 ",
"chainType ": "None ",
"configurationRequired ": false,
"iconUrl ": "https://external-audience-selector.s10.marketingcloudapps.com/ga360/ga360-logo.svg ",
"title ": " ",
"entrySourceGroupConfigUrl ": "https://external-audience-selector.s10.marketingcloudapps.com/ga360/entrysourcegroupconfig.json ",
"sourceInteractionId ": "00000000-0000-0000-0000-000000000000 "
}
}
];
}
function GetTriggersAsSalesforceData()
{
return [
{
"key ": "TRIGGER ",
"name ": "TRIGGER ",
"description ": " ",
"type ": "Event ",
"outcomes ": [],
"arguments ": {},
"configurationArguments ": {},
"metaData ": {
"eventDefinitionKey ": "ContactEvent-2c696b5a-dfca-bab2-8f50-75a5d2102fd6 ",
"chainType ": "None ",
"configurationRequired ": true,
"iconUrl ": "/jbint-events/images/icon_journeyBuilder-entrySource-Salesforce_white.svg ",
"title ": "Salesforce Data ",
"category ": "Event ",
"entrySourceGroupConfigUrl ": "https://jbinteractions.s10.marketingcloudapps.com/jbint-events/entrysourcegroupconfig.json ",
"sourceInteractionId ": "00000000-0000-0000-0000-000000000000 "
}
}
];
}
function GetTriggersAsInBound()
{
return [
{
"key ": "TRIGGER ",
"name ": "TRIGGER ",
"description ": " ",
"type ": "Event ",
"outcomes ": [],
"arguments ": {},
"configurationArguments ": {},
"metaData ": {
"eventDefinitionKey ": "ContactEvent-210b030c-62fa-5046-2350-655304701b1c ",
"chainType ": "None ",
"configurationRequired ": true,
"iconUrl ": "https://jb-chat-messaging.s10.marketingcloudapps.com/inbound-chat/images/icon.svg ",
"title ": "Inbound Chat ",
"category ": "Event ",
"entrySourceGroupConfigUrl ": "6EC1B29B-1A59-4854-AC57-ABF03035FBBA ",
"sourceInteractionId ": "00000000-0000-0000-0000-000000000000 "
}
}
];
}
function GetTriggersAsInAppMessage()
{
return [
{
"key ": "TRIGGER ",
"name ": "TRIGGER ",
"description ": " ",
"type ": "Event ",
"outcomes ": [],
"arguments ": {},
"configurationArguments ": {},
"metaData ": {
"eventDefinitionKey ": "ContactEvent-6b4f2864-d3bf-b2f4-7327-3ad26ca0087c ",
"chainType ": "None ",
"configurationRequired ": true,
"iconUrl ": "/images/in-app-engagement-entry/in-app-message.svg ",
"title ": "In-App Message Event ",
"category ": "Event ",
"entrySourceGroupConfigUrl ": "jb:///data/entry/in-app-engagement/entrysourcegroupconfig.json ",
"sourceInteractionId ": "00000000-0000-0000-0000-000000000000 "
}
}
];
}
function JourneyActivitiesFinale()
{
return [
{
"key": "MULTICRITERIADECISIONV2-1",
"name": "",
"description": "",
"type": "MULTICRITERIADECISION",
"outcomes": [
{
"key": "default_path_1",
"next": "EMAILV2-3",
"arguments": {},
"metaData": {
"label": "Consent",
"skipI18n": true,
"isLabelFromConversion": false,
"criteriaDescription": "EmailConsent is True",
"invalid": false
}
},
{
"key": "remainder_path",
"next": "EMAILV2-4",
"arguments": {},
"metaData": {
"label": "Remainder",
"invalid": false
}
}
],
"arguments": {},
"configurationArguments": {
"criteria": {
"default_path_1": "<FilterDefinition><ConditionSet Operator=\"AND\" ConditionSetName=\"Individual Filter Grouping\"><Condition IsEphemeralAttribute=\"true\" Key=\"Event.DEAudience-c8b9f2bb-d96b-096b-58d7-0dc9d7568134.EmailConsent\" Operator=\"Is\" UiMetaData=\"{}\"><Value><![CDATA[true]]></Value></Condition></ConditionSet></FilterDefinition>"
},
"schemaVersionId": "252"
},
"metaData": {
"isConfigured": true
},
"schema": {
"arguments": {
"actualChoice": {
"dataType": "Number",
"isNullable": false,
"direction": "Out",
"readOnly": false,
"access": "Hidden"
},
"filterResult": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": true,
"access": "Hidden"
}
}
}
},
{
"key": "WAITBYDURATION-4",
"name": "1 day",
"description": "",
"type": "WAIT",
"outcomes": [
{
"key": "3590fe0d-7f50-4c56-b0c1-d10dd46557d9",
"arguments": {},
"metaData": {
"invalid": false
}
}
],
"arguments": {},
"configurationArguments": {
"waitDuration": 1,
"waitUnit": "DAYS"
},
"metaData": {
"isConfigured": true,
"uiType": "WAITBYDURATION"
},
"schema": {
"arguments": {
"endDate": {
"dataType": "Date",
"isNullable": false,
"direction": "Out",
"readOnly": false,
"access": "Hidden"
},
"waitEndDateAttributeDataBound": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"waitDefinitionId": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"waitForEventId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"executionMode": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"startActivityKey": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"waitQueueId": {
"dataType": "LongNumber",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
}
}
}
},
{
"key": "WAITBYDURATION-5",
"name": "1 day",
"description": "",
"type": "WAIT",
"outcomes": [
{
"key": "51591072-5be1-4d50-9291-03781ee1f54b",
"arguments": {},
"metaData": {
"invalid": false
}
}
],
"arguments": {},
"configurationArguments": {
"waitDuration": 1,
"waitUnit": "DAYS"
},
"metaData": {
"isConfigured": true,
"uiType": "WAITBYDURATION"
},
"schema": {
"arguments": {
"endDate": {
"dataType": "Date",
"isNullable": false,
"direction": "Out",
"readOnly": false,
"access": "Hidden"
},
"waitEndDateAttributeDataBound": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"waitDefinitionId": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"waitForEventId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"executionMode": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"startActivityKey": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"waitQueueId": {
"dataType": "LongNumber",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
}
}
}
},
{
"key": "EMAILV2-3",
"name": "Email 1",
"description": "",
"type": "EMAILV2",
"outcomes": [
{
"key": "2e665544-5e40-4b79-a729-aa629922c5a9",
"next": "WAITBYDURATION-4",
"arguments": {},
"metaData": {
"invalid": false
}
}
],
"arguments": {},
"configurationArguments": {
"isModified": true,
"googleAnalyticsCampaignName": "",
"triggeredSend": {
"autoAddSubscribers": true,
"autoUpdateSubscribers": true,
"bccEmail": "",
"ccEmail": "",
"created": {},
"domainExclusions": [],
"dynamicEmailSubject": "Email 1",
"emailId": 83303,
"emailSubject": "Email 1",
"exclusionFilter": "",
"isSalesforceTracking": true,
"isMultipart": true,
"isSendLogging": true,
"isStoppedOnJobError": false,
"modified": {},
"preHeader": "",
"priority": 4,
"sendClassificationId": "1858801a-99ba-e911-80e4-1402ec74dd4d",
"throttleOpens": "1/1/0001 12:00:00 AM",
"throttleCloses": "1/1/0001 12:00:00 AM",
"deliveryProfileId": "1758801a-99ba-e911-80e4-1402ec74dd4d",
"senderProfileId": "1a58801a-99ba-e911-80e4-1402ec74dd4d",
"isTrackingClicks": true,
"publicationListId": 10280
},
"applicationExtensionKey": "jb-email-activity"
},
"metaData": {
"category": "message",
"version": "1.0",
"icon": "https://jb-email-activity.s10.marketingcloudapps.com/img/email-icon.svg",
"iconSmall": "https://jb-email-activity.s10.marketingcloudapps.com/img/email-icon.svg",
"statsContactIcon": null,
"original_icon": "/img/email-icon.svg",
"original_iconSmall": "/img/email-icon.svg",
"sections": {},
"isConfigured": true
},
"schema": {
"arguments": {
"requestID": {
"dataType": "Text",
"isNullable": true,
"direction": "Out",
"readOnly": false,
"access": "Hidden"
},
"messageKey": {
"dataType": "Text",
"isNullable": true,
"direction": "Out",
"readOnly": false,
"access": "Hidden"
},
"activityId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"definitionId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": true,
"access": "Hidden"
},
"emailSubjectDataBound": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": true,
"access": "Hidden"
},
"contactId": {
"dataType": "Number",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"contactKey": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"emailAddress": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"sourceCustomObjectId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"sourceCustomObjectKey": {
"dataType": "LongNumber",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"fieldType": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"eventData": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"obfuscationProperties": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"customObjectKey": {
"dataType": "LongNumber",
"isNullable": true,
"direction": "In",
"readOnly": true,
"access": "Hidden"
},
"definitionInstanceId": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
}
}
}
},
{
"key": "EMAILV2-4",
"name": "Email 1",
"description": "",
"type": "EMAILV2",
"outcomes": [
{
"key": "3f8e5e6a-5dd9-4573-a71b-3da939d52ef0",
"next": "WAITBYDURATION-5",
"arguments": {},
"metaData": {
"invalid": false
}
}
],
"arguments": {},
"configurationArguments": {
"isModified": true,
"googleAnalyticsCampaignName": "",
"triggeredSend": {
"autoAddSubscribers": true,
"autoUpdateSubscribers": true,
"bccEmail": "",
"ccEmail": "",
"created": {},
"domainExclusions": [],
"dynamicEmailSubject": "Email 1",
"emailId": 83303,
"emailSubject": "Email 1",
"exclusionFilter": "",
"isSalesforceTracking": true,
"isMultipart": true,
"isSendLogging": true,
"isStoppedOnJobError": false,
"modified": {},
"preHeader": "",
"priority": 4,
"sendClassificationId": "1858801a-99ba-e911-80e4-1402ec74dd4d",
"throttleOpens": "1/1/0001 12:00:00 AM",
"throttleCloses": "1/1/0001 12:00:00 AM",
"deliveryProfileId": "1758801a-99ba-e911-80e4-1402ec74dd4d",
"senderProfileId": "1a58801a-99ba-e911-80e4-1402ec74dd4d",
"isTrackingClicks": true,
"publicationListId": 10280
},
"applicationExtensionKey": "jb-email-activity"
},
"metaData": {
"category": "message",
"version": "1.0",
"icon": "https://jb-email-activity.s10.marketingcloudapps.com/img/email-icon.svg",
"iconSmall": "https://jb-email-activity.s10.marketingcloudapps.com/img/email-icon.svg",
"statsContactIcon": null,
"original_icon": "/img/email-icon.svg",
"original_iconSmall": "/img/email-icon.svg",
"sections": {},
"isConfigured": true
},
"schema": {
"arguments": {
"requestID": {
"dataType": "Text",
"isNullable": true,
"direction": "Out",
"readOnly": false,
"access": "Hidden"
},
"messageKey": {
"dataType": "Text",
"isNullable": true,
"direction": "Out",
"readOnly": false,
"access": "Hidden"
},
"activityId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"definitionId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": true,
"access": "Hidden"
},
"emailSubjectDataBound": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": true,
"access": "Hidden"
},
"contactId": {
"dataType": "Number",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"contactKey": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"emailAddress": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"sourceCustomObjectId": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"sourceCustomObjectKey": {
"dataType": "LongNumber",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"fieldType": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"eventData": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"obfuscationProperties": {
"dataType": "Text",
"isNullable": true,
"direction": "In",
"readOnly": false,
"access": "Hidden"
},
"customObjectKey": {
"dataType": "LongNumber",
"isNullable": true,
"direction": "In",
"readOnly": true,
"access": "Hidden"
},
"definitionInstanceId": {
"dataType": "Text",
"isNullable": false,
"direction": "In",
"readOnly": false,
"access": "Hidden"
}
}
}
}
];
}
try {
// Get the access token by calling the 'getAccessToken' function
var accessToken = 'Bearer ' + getAccessToken();
// Replace 'definitionId' with the actual ID you want to retrieve
var definitionId = 'your-definition-id';
// Define the URL for retrieving summary information about an interaction (journey)
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/interaction/v1/interactions';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accessToken];
var contentType = "application/json;charset=UTF-8";
var guid=Platform.Function.GUID();
var payload={
"key": "Reverse-Engineering-APIEvent-finale",
"name": "Reverse-Engineering-APIEvent-finale",
"description": "reverse engineering",
"categoryId":GetCategoryIDForJourney(),
"workflowApiVersion": 1,
"triggers":GetTriggersAsAPIEvent(),
"activities":JourneyActivitiesFinale()
}
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.POST(setupURL,contentType,Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response containing summary information
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://tenantendpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
var page = 1;
var pageSize = 100;
// Define the URL for deleting contacts by their keys
var setupURL = 'https://tenantendpoint.rest.marketingcloudapis.com/interaction/v1/interactions/journeyhistory/search?$page=' + page + '&$pageSize=' + pageSize;
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload
var payload = '';
// Send an HTTP POST request
var httpResponse = HTTP.Post(setupURL, "application/json", payload, headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response from the contact deletion
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = '';
// Replace with your client ID
var ClientSecret = '';
// Replace with your client secret
var url = 'https://tenantEndpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
}
catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
var page=1;
var pageSize=100;
var setupURL = 'https://tenantEndpoint.rest.marketingcloudapis.com/interaction/v1/interactions/journeyhistory/search?$page=' + page + '&$pageSize=' + pageSize;
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for deleting contacts by their keys
var payload ={
"definitionIds": [],
"activityTypes": [],
"start": "2023-01-01T06:00:00.000Z",
"end": null,
"statuses": []
};
// Send an HTTP POST request to delete contacts by their keys
var httpResponse = HTTP.Post(setupURL, "application/json", Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
//var response =httpResponse["Response"][0];
// Display the response from the contact deletion
Write(Stringify(httpResponse));
}
catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = '';
// Replace with your client ID
var ClientSecret = '';
// Replace with your client secret
var url = 'https://tenantEndpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
}
catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
var page=1;
var pageSize=100;
var setupURL = 'https://tenantEndpoint.rest.marketingcloudapis.com/interaction/v1/interactions/journeyhistory/search?$page=' + page + '&$pageSize=' + pageSize;
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for deleting contacts by their keys
var payload ={
"contactKeys": [
"1234567890"
],
"definitionIds": [],
"activityTypes": [],
"start": "2023-01-01T06:00:00.000Z",
"end": null,
"statuses": []
};
// Send an HTTP POST request to delete contacts by their keys
var httpResponse = HTTP.Post(setupURL, "application/json", Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
//var response =httpResponse["Response"][0];
// Display the response from the contact deletion
Write(Stringify(httpResponse));
}
catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
// Replace with your client ID and client secret
var clientId = '';
var clientSecret = '';
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var contentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": clientId,
"client_secret": clientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, contentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write("Error in getAccessToken: " + e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accessToken = 'Bearer ' + getAccessToken();
// Define the URL for retrieving summary information about automation
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/automation/v1/automations?view=targetdes';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accessToken];
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.Get(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Status"];
var response = httpResponse["Content"];
// Display the response containing summary information
Write("HTTP Status Code: " + statusCode);
Write("Response: " + Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write("Error in main script: " + e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = '';
// Replace with your client ID
var ClientSecret = '';
// Replace with your client secret
var url = 'https://tenantEndpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
}
catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
var setupURL = 'https://tenantEndpoint.rest.marketingcloudapis.com/automation/v1/automations';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for deleting contacts by their keys
var payload ={
"name":"Automation API Created"
};
// Send an HTTP POST request to delete contacts by their keys
var httpResponse = HTTP.Post(setupURL, "application/json", Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response =httpResponse["Response"];
// Display the response from the contact deletion
Write(Stringify(response));
}
catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
// Replace with your client ID and client secret
var clientId = '';
var clientSecret = '';
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var contentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": clientId,
"client_secret": clientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, contentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write("Error in getAccessToken: " + e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accessToken = 'Bearer ' + getAccessToken();
var Id='';
// Define the URL for retrieving summary information about automation
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/automation/v1/automations/'+Id;
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accessToken];
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.Get(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Status"];
var response = httpResponse["Content"];
// Display the response containing summary information
Write("HTTP Status Code: " + statusCode);
Write("Response: " + Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write("Error in main script: " + e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = '';
// Replace with your client ID
var ClientSecret = '';
// Replace with your client secret
var url = 'https://tenantEndpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
}
catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
var Id='';
var setupURL = 'https://tenantEndpoint.rest.marketingcloudapis.com/automation/v1/automations'+Id+'/actions/runallonce';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload for deleting contacts by their keys
var payload ='';
// Send an HTTP POST request to delete contacts by their keys
var httpResponse = HTTP.Post(setupURL, "application/json", Stringify(payload), headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response =httpResponse["Response"];
// Display the response from the contact deletion
Write(Stringify(httpResponse));
}
catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
// Replace with your client ID and client secret
var clientId = '';
var clientSecret = '';
var url = 'https://DOMAIN.auth.marketingcloudapis.com/v2/token';
var contentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": clientId,
"client_secret": clientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, contentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write("Error in getAccessToken: " + e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accessToken = 'Bearer ' + getAccessToken();
var Id='';
// Define the URL for retrieving summary information about automation
var setupURL = 'https://DOMAIN.rest.marketingcloudapis.com/automation/v1/automations/category/'+Id+'?view=targetdes';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accessToken];
// Send an HTTP GET request to retrieve summary information
var httpResponse = HTTP.Get(setupURL, headerNames, headerValues);
var statusCode = httpResponse["Status"];
var response = httpResponse["Content"];
// Display the response containing summary information
Write("HTTP Status Code: " + statusCode);
Write("Response: " + Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write("Error in main script: " + e.message);
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://tenantendpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for definitionlogs
var setupURL = 'https://tenantendpoint.rest.marketingcloudapis.com/interaction/v1/interactions/definitionlogs/search';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload
var payload = '';
// Send an HTTP POST request
var httpResponse = HTTP.Post(setupURL, "application/json", payload, headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response from the contact deletion
Write(Stringify(response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://tenantendpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for journeyhistory summary
var setupURL = 'https://tenantendpoint.rest.marketingcloudapis.com/interaction/v1/interactions/journeyhistory/summary';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload
var payload = '';
// Send an HTTP POST request
var httpResponse = HTTP.Post(setupURL, "application/json", payload, headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response from the contact deletion
Write((response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
<script runat="server" language="javascript">
// Load the Marketing Cloud Core library
Platform.Load("core", "1");
// Function to obtain an access token using client credentials
function getAccessToken() {
var ClientId = ''; // Replace with your client ID
var ClientSecret = ''; // Replace with your client secret
var url = 'https://tenantendpoint.auth.marketingcloudapis.com/v2/token';
var ContentType = 'application/json';
// Create a payload for the access token request
var payload = {
"client_id": ClientId,
"client_secret": ClientSecret,
"grant_type": "client_credentials"
};
try {
// Send an HTTP POST request to obtain the access token
var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).access_token;
// Store the access token in a named variable for later use
Variable.SetValue("@accessToken", accessToken);
// Return the access token for use in the main script
return accessToken;
} catch (e) {
// Handle any errors that may occur during the access token request
Write(e.message);
}
}
try {
// Get the access token by calling the 'getAccessToken' function
var accesstoken = 'Bearer ' + getAccessToken();
// Define the URL for journeyhistory summary
var setupURL = 'https://tenantendpoint.rest.marketingcloudapis.com/interaction/v1/interactions/journeyhistory/timeseries';
// Define the headers for the HTTP request
var headerNames = ["Authorization"];
var headerValues = [accesstoken];
// Create a payload
var payload = '';
// Send an HTTP POST request
var httpResponse = HTTP.Post(setupURL, "application/json", payload, headerNames, headerValues);
var statusCode = httpResponse["StatusCode"];
var response = httpResponse["Response"][0];
// Display the response from the contact deletion
Write((response));
} catch (e) {
// Handle any errors that may occur during the main script execution
Write(Stringify(e));
}
</script>
Comments
Post a Comment