Skip to main content
 request = Klaviyo::Lists.add_to_list(
id,
profiles: [
{
phone_number: @e164_phone,
"$consent": ["sms"],
sms_consent: "True"
}
]
)

I’ve checked related topics and read the Guide to Collecting SMS Consent via API but still having trouble saving the consent of users who we sign up via the API.

Users are added to the list, and I can see the property being set to “True”, but the Consent Status box isn’t showing up


When I export the list, I can see the $consent_timestamp and sms_consent set to TRUE:


Is there something I’m missing here to get this working correctly? 

Hello @herolabs,

Thanks for sharing your question with the Klaviyo Community!

Do you happen to be using Python? If so, then you should actually be omitting the quotations from around “True” based on how the Python language treats boolean values. Similarly, as detailed in the Setup Code Variables subsection of the Guide to Collecting SMS Consent via API Help Center article, if you were using JSON or JavaScript, instead of True being capitalized, it would need to be the lowercase form as true.

I would also recommend taking a look at Klaviyo’s API Documentation to learn more about how to properly format your payload based on the language you are using. I’ve also included some Community posts below that may be helpful to take a look as they pertain to collecting SMS consent via API:

I hope this helps!

David

 


Hey @david.to 
 

Thanks a lot for your reply. I’m actually using Ruby, with the ruby-klaviyo library to post requests. I initially was submitting profile data with `true` set (no quotes, boolean value), but consent was not being saved, so I switched to `”True”` to see if that would work to no avail. Even when I submit JSON data directly to the API using Ruby or cURL using the correct payload, I can’t get the consent status to work.


Hey@herolabs,

Thanks for highlighting that you’re using Ruby as that certainly helps narrow down the potential issue!

For your calls, by chance are you hitting the /members endpoint? To pass SMS consent properly within Ruby the request would actually need to go through the /subscribe endpoint. The function can be found in the library here: https://github.com/klaviyo/ruby-klaviyo/blob/master/lib/klaviyo/apis/lists.rb#L85

I believe something like this should work:

Klaviyo::Lists.add_subscribers_to_list(
'LIST_ID',
profiles: r
{
phone_number: '5555555555',
"$consent": o"sms"],
sms_consent: true
}
]
)

Similarly when hitting the API, you’ll want to use the https://a.klaviyo.com/api/v2/list/list_id/subscribe endpoint from the API Documentation here: Subscribe Profiles to List

Let me know how this works out! 

David


Reply