Follow this documentation when setting up APIs forms that trigger an SMS pre-opt-in message from mobile connect.
Create all SMS Pre-Opt-In Message in the UPMC Business Unit
All pre opt-in messages should be created in the UPMC BU.
The first section of code is setting all the SSJS variables and getting the Authentication Bearer
- Prekeyword is what the phone number will be opted into when the first SMS message goes out. The message will contain the keyword we want them to opt in to. This needs to be created in the UPMC BU
- MessageAPIKey is an API outbound message that will be used as the first step of the double opt-in message. This needs to be created in the UPMC BU
- client_id client_secret are the API login credentials to get to get access to execute an API
- accountID is the BU where we are executing this code
/******** SMS REPLY TO OPT IN ********/
SET @keyword = ‘WOMEN’
SET @prekeyword = ‘PREWOMEN”
SET @MessageAPIKey = ‘MjAwOjc4OjA’
SET @accountID = ‘7200479’ /* SMS MESSAGE BUILT IN UPMC BU */
]%%
<script runat=”server”>
Platform.Load(“Core”,”1.1.1″);
var phone_number = “1” + Platform.Variable.GetValue(“@phone_number”),
email_address = Platform.Variable.GetValue(“@email_address”);
keyword = Platform.Variable.GetValue(“@keyword”);
prekeyword = Platform.Variable.GetValue(“@prekeyword”);
MessageAPIKey = Platform.Variable.GetValue(“@MessageAPIKey”);
accountID = Platform.Variable.GetValue(“@accountID”);
if(phone_number != ”) {
try {
/*********************** Get Authenication token *********************/
var authEndpoint = “https://mcdw3xqqr5zvbbnr93flxd4v425y.auth.marketingcloudapis.com”; //provide authentication endpoint
var payload = {
grant_type: “client_credentials”,
client_id: “1u7t6asuey4r6xtbzr3lnox0”, //provide Client Id
client_secret: “nCjFQ85HHdD0baEATNVdxyTZ”, //provide Client Secret
scope: “sms_read sms_write sms_send”, //provide Client Secret
account_id: accountID
};
var url = authEndpoint + “/v2/token”;
var contentType = “application/json”;
Write(Stringify(payload));
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;
}
/*********************** Get Authenication token *********************/
The second section of code is firing the SMS message. At this point we have the Access Token to perform an SMS message.
/********** Make a call using the messageContact route ********************/
/* Write(Stringify(accessToken)); */
var headerNames = [“Authorization”];
var headerValues = [“Bearer ” + accessToken];
var smsEndpoint = “https://mcdw3xqqr5zvbbnr93flxd4v425y.rest.marketingcloudapis.com/”; //provide rest endpoint
var smsPayload = {
“mobileNumbers”: [ phone_number ],
“Subscribe”: true,
“Resubscribe”: true,
“keyword”: prekeyword
};
Write(Stringify(smsPayload));
var smsUrl = smsEndpoint + “sms/v1/messageContact/”+MessageAPIKey+”/send”; //provide message API key
Write(smsUrl);
var sendSMS = HTTP.Post(smsUrl, contentType, Stringify(smsPayload), headerNames, headerValues);
/********** Make a call using the messageContact route ********************/
} catch (error) {
Write(Stringify(error));
}
}
</script>
Note: Be sure to include subscribe and resubscribe = true in the code.
Check to see if a specific phone number has been added to a keyword:
Note: Be sure to include subscribe and resubscribe = true in the code.
Check these previous APIs for reference:
ASP.NET Form APIs
Magee Lemieux (Women’s Health) API
BC Task: https://3.basecamp.com/4154990/buckets/11394777/todos/3130767624
Documentation: https://upmc-sfmc.flyingcork.com/configuration-types/asp-net-api/magee-lemieux-womens-health-api/
Orthopaedics Brand Campaign (2020) API
BC Task: https://3.basecamp.com/4154990/buckets/10977719/todos/3011240870
Documentation: https://upmc-sfmc.flyingcork.com/configuration-types/asp-net-api/orthopaedics-brand-campaign-2020-api/
Sitecore Form APIs
Magee Brand We Deliver Joy API
BC Task: https://3.basecamp.com/4154990/buckets/11394777/todos/4234098893
Documentation: https://upmc-sfmc.flyingcork.com/business-units/upmc/magee-brand-we-deliver-joy-api/
COVID (Transition to HB) API
BC Task: https://3.basecamp.com/4154990/buckets/22135104/todos/3949093951
Documentation: https://upmc-sfmc.flyingcork.com/business-units/upmc/covid-transition-to-hb-api/