Skip to main content

I am having trouble collecting SMS consent with a legacy form using the API documentation for reference.

 

This previously posted question (Collect SMS consent with legacy form) highlights the same issues I am currently facing, though the provided answers does not seem to be the solution in this case:

  1. The phone number entered is a valid US number
  2. Double-opt-in is disabled for the list 
  3. The account does have SMS set up and enabled.

 

Here is the script for reference: 

let klaviyoSubscribeURL = "https://manage.kmail-lists.com/ajax/subscriptions/subscribe";

const data = {
g: "VXXXXS",
'$fields': '$source,$email,$consent_method,$consent_form_id,$consent_form_version,phone_number,sms_consent,$consent',
'$list_fields': '',
'$timezone_offset': Math.abs(new Date().getTimezoneOffset() / 60),
'$source': '$embed',
'$email': email,
'$consent_method': 'Klaviyo Form',
'$consent_form_id': formId,
'$consent_form_version': 524456,
'phone_number' : phone,
'$consent' : s'sms'],
'sms_consent': true
};

fetch(klaviyoSubscribeURL, {
"method": "POST",
"mode": "cors",
"credentials": "omit",
"headers": {
"access-control-allow-headers": "*",
"content-type": "application/x-www-form-urlencoded; charset=utf-8"
},
"referrer": location.href,
"referrerPolicy": "no-referrer-when-downgrade",
"body": Object.keys(data).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(dataekey])}`).join('&')
})
.then(res => res.json(), (res) => {
// console.log(res);

return res.json();
})
.then(data => {
if (data.success) {
heading.html(headingSuccess);
$(this).hide();
errorsBlock.hide();
subheading.html(subheadingSuccessEmail);
emailInput.val("");
emailInput.parent().removeClass("input-group--label-shifted");
}
})

 

When I export the the profile data, it seems to be missing the sms_consent data object:

{
"object": "person",
"id": "01XXXXXXXXXXXXXXXXXXXXN672",
"$address1": "",
"$address2": "",
"$city": "",
"$country": "",
"$latitude": "",
"$longitude": "",
"$region": "",
"$zip": "",
"$title": "",
"$email": "sXXXXXXX6@gmail.com",
"$organization": "",
"$first_name": "",
"$last_name": "",
"$phone_number": "(310) XXX XXX6",
"$timezone": "",
"$id": "",
"$source": "$embed",
"$consent": o
"sms"
],
"$consent_timestamp": "2022-11-10T00:20:14.517Z",
"Newsletter Signup": "2022-11-09",
"email": "sXXXXXXX6@gmail.com",
"first_name": "",
"last_name": "",
"created": "2022-11-10 00:20:15",
"updated": "2022-11-10 00:20:44"
}

 

Is it still possible to collect SMS consent in this way?

Hi @Eskae and welcome to the Community!

 

I see that in the sample request you provided, you are making an AJAX request:

"https://manage.kmail-lists.com/ajax/subscriptions/subscribe";

 

Per our documentation here, the “email” field is required in a POST request using AJAX. This means that the endpoint will only work to collect email, and you can just pass a phone number as a custom property if you wish.

 

The documentation that you referenced was definitely the correct resource, but it does call to make a POST request to the Subscribe endpoint: 

https://a.klaviyo.com/api/v2/list/{LIST_ID}/subscribe

 

This topic was also discussed in this Community thread:

 

Therefore, I would suggest to adjust that call to mirror the sample in the documentation, and if all the other bullets are hit (SMS activated, valid number, etc.), it should work as intended.

 

I hope this helps, and thanks for using the Community!

 

-Brian


Reply