Hey Did someone figure out how to add sms consent in php-sdk klaviyo from laravel

  • 27 August 2021
  • 7 replies
  • 355 views

Userlevel 1
Badge +2

So I’ve this code but it dont add the sms consent to the site, only email consent is working, Does anyone know how to do it?

 

    public function chnages()

    {

        $client = new Klaviyo('Klaviyo_Private_key', 'Klaviyo_Public_key');

        $profile = new KlaviyoProfile(

            array(

                '$email' => 'thomas2.jefferson@mailinator.com',

                '$first_name' => 'Thomas12',

                '$last_name' => 'Jefferson',

                '$consent' => ["sms","email"],

                'sms_consent' => True,

                '$phone_number' => "12345678900",

                'Plan' => 'Premium'

            )

        );

        $client->lists->addSubscribersToList('LIST_ID', array($profile));

    }

MeetAmin 2 years ago

Hey @Dov ,

Absolutly and here is the answerd link of mine on stackoverflow for refrence if someone gets stuck then check this sample php snippet too.

View original

7 replies

Userlevel 5
Badge +34

Hi @MeetAmin,

Thanks for reaching out in the Klaviyo Community! Have you seen our sample code for syncing SMS via API in our Guide to Collecting SMS Consent via API? I can see the code that you shared is a bit different than the code below so I’d recommend taking a peek and let us know if that helps to resolve the issue!

import requests
import json
data = {
"api_key": "PRIVATE_API_KEY",
"profiles": [
{
"$consent": ["sms"],
"phone_number": "+12345678900",
"sms_consent": True
}
]
}
headers = {
"Content-Type": "application/json",
"Cache-Control": "no-cache"
}
conv = json.dumps(data)
response = requests.request("POST", "https://a.klaviyo.com/api/v2/list/{LIST_ID}/subscribe", data=conv, headers=headers)
print(response.text)

Have a nice weekend!

Julie 

Userlevel 1
Badge +2

Hey and this seems to be in python or java correct? Or Is it for Php Sdk tool? Little confused, or is it simple json?

@julie.accardo 

Userlevel 1
Badge +2

@julie.accardo Its python, but is there a way to do it all in php with subscribe end-point?

 

Userlevel 1
Badge +2

@Dov  Hey Ive created this thread, Can you please explain how to collect an sms and email consent from klaivyo with php, Well Basically I’m using laravel and i tried this php sdk too, No luck so far. As of now our present site is integrated with klavio’s woocom plugin on wordpress but I gotta try it with laravel, is it possible to do it with api from a form request?

Userlevel 1
Badge +2

Hey everyone, After a lot of time I found a way to add the users in their appropriate lists(with green checks next to email and number --same as woocom). Basically what my code does it when you check the consent for email it’ll send it to its email’s list, then when we check only sms it sends it to different list...Not hard correct?Correct it isn’t that hard to just send them to different list but where we get stuck is with consent status (Green check next to email and Phonenumber). After looking around here is the code which would do it. Remember why klaviyo people say subscibe endpoint means the curl or whatever url it is has to be subscribe url like this. Feel free to suggest or ask if anyone is having issue with custom integration or with laravel(php).  @julie.accardo

Userlevel 7
Badge +61

Hi @MeetAmin,

Thank you so much for sharing this information with the Community! This will be helpful information for other members to reference in the future :)

Userlevel 1
Badge +2

Hey @Dov ,

Absolutly and here is the answerd link of mine on stackoverflow for refrence if someone gets stuck then check this sample php snippet too.

Reply