There are two steps you can use to call the ReSci API with a custom keyed entry field on your desktop computer. To send a phone number to the ReSci system from JavaScript, you can call the ReSci public API with the user’s phone number and your campaign ID.
Step One
Make a POST request to: https://vyg.mobi/api/TrackingEvents/SubscribeNumber
Use the data object below for the post request:
{
PhoneIn: <phone starting with +1> (e.g., +13108293002),
CampaignId: <campaignId> (e.g., 1234)
}
Possible Responses:
- 200: Already Subscribed
- 201: Subscribed Successful
Step Two
Below is a JavaScript example that you can use to send the phone number to ReSci. You will need to pass the two variables below to our system.
Note: The phone number must be formatted correctly to subscribe to our system.
<script type="text/javascript">
function formatPhoneNumberToInternational(value) {
var normalized = normalizePhoneNumber(value);
var international = '+1' + normalized;
return international;
}
function normalizePhoneNumber(value) {
var normalized = value;
if (value) {
var onlyNums = value.replace(/[^\d]/g, '');
normalized = onlyNums.slice(0, 10);
}
return normalized;
}
function subscribe(phoneNumber, campaignId) {
var XHR = ("onload" in new XMLHttpRequest()) ? XMLHttpRequest : XDomainRequest;
var xhr = new XHR();
xhr.open("POST",”https://vyg.mobi/api/TrackingEvents/SubscribeNumber", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({
PhoneIn: formatPhoneNumberToInternational(phoneNumber),
CampaignId: campaignId
}));
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
if (xhr.status == 201) {
//Subscribed
} else if (xhr.status == 200) {
//Already Subscribed
} else {
//Failed
}
};
}
</script>
Comments
0 comments
Please sign in to leave a comment.