Skip to content

Instantly share code, notes, and snippets.

@zuzannamj
Last active April 21, 2023 01:05
Show Gist options
  • Save zuzannamj/94a0b083fdef2960c0d654f6d1a26813 to your computer and use it in GitHub Desktop.
Save zuzannamj/94a0b083fdef2960c0d654f6d1a26813 to your computer and use it in GitHub Desktop.
<script runat="server">
Platform.Load("Core","1.1.1");
try {
//API authentication
var authEndpoint = ""; //provide authentication endpoint
var payload = {
clientId: "", //provide Client Id
clientSecret: "" //provide Client Secret
};
var url = authEndpoint + "/v1/requestToken";
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.accessToken;
}
//make a call using the messageContact route
var headerNames = ["Authorization"];
var headerValues = ["Bearer " + accessToken];
var smsEndpoint = ""; //provide rest endpoint
var smsPayload = {
"mobileNumbers": [
"" //pass phone number
],
"Subscribe": true,
"Resubscribe": true,
"keyword": "" //provide KEYWORD
};
var smsUrl = smsEndpoint + "/sms/v1/messageContact/xxxxxxxxx/send"; //provide message API key
var sendSMS = HTTP.Post(smsUrl, contentType, Stringify(smsPayload), headerNames, headerValues);
} catch (error) {
Write(Stringify(error));
}
</script>
@rain89146
Copy link

this code is broken in every way, the HTTP.Post doesn't work at all

@zuzannamj
Copy link
Author

@rain89146 I just checked and the code works just fine, I even set up a CloudPage with the above code (unfortunately it only works with Polish phone numbers) - https://mcg7y3r488-d6mcg1dym88btc7g4.pub.sfmc-content.com/x1p4cdfw5ud
I suggest you take your code to https://salesforce.stackexchange.com/ and have someone help you fix it there instead of making vicious comments

@EndlessMauve
Copy link

Hi @zuzannamj Thank you for posting this! How to modify this code to send to a Data Extension with over 100 records? Cannot wrap my head around it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment