Last active
April 15, 2024 23:30
-
-
Save zuzannamj/115ca32567e33089848da40880eaf402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%[ | |
SET @emailAddress = AttributeValue("emailaddr") | |
/* if needed, fetch other parameters passed from the CloudPagesURL function*/ | |
IF NOT EMPTY(@emailAddress) THEN | |
]%% | |
<script runat="server"> | |
Platform.Load("Core", "1"); | |
try { | |
var email = Variable.GetValue("@emailAddress") | |
//authenticate to get access token | |
var authEndpoint = 'https://{{your endpoint}}.auth.marketingcloudapis.com/' //add your tenant specific endpoint | |
var payload = { | |
client_id: {{client Id}}, //add your client id | |
client_secret:{{client Secret}}, //add your client secret | |
grant_type: "client_credentials" | |
}; | |
var url = authEndpoint + '/v2/token' | |
var contentType = 'application/json' | |
var accessTokenRequest = HTTP.Post(url, contentType, Stringify(payload)); | |
if (accessTokenRequest.StatusCode == 200) { | |
var tokenResponse = Platform.Function.ParseJSON(accessTokenRequest.Response[0]); | |
var accessToken = tokenResponse.access_token | |
var rest_instance_url = tokenResponse.rest_instance_url | |
}; | |
//make api call to release subscriber from the Wait Until Activity | |
if (email != null && accessToken != null) { | |
var headerNames = ["Authorization"]; | |
var headerValues = ["Bearer " + accessToken]; | |
var jsonBody = { | |
"ContactKey": {{ContactKey}}, //pass the Contact Key | |
"EventDefinitionKey": {{Wait Until Activity API Key}}, //add the Wait Until Activity API Key | |
"Data": { | |
//in the payload pass any data required in your data extension and | |
//include the data as defined in the filter criteria in Wait Until Activity definition | |
} | |
}; | |
var requestUrl = rest_instance_url + "/interaction/v1/events"; | |
var fireEntryEvent = HTTP.Post(requestUrl, contentType, Stringify(jsonBody), headerNames, headerValues); | |
var respo = fireEntryEvent.Response.toString(); | |
if (fireEntryEvent.StatusCode == 201) { | |
Redirect('https://www.salesforce.com',false); //define the link where subscriber should be redirected | |
} | |
}; | |
} catch (error) { | |
Write("<br><h2>Sorry, something went wrong.</h2><br>" + Stringify(error)); | |
} | |
</script> | |
%%[ELSE]%% | |
Sorry, something went wrong. | |
%%[ENDIF]%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment