Skip to main content

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


Forum|alt.badge.img+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));

    }

Pinned reply

September 1, 2021

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.

Did this topic or the replies in the thread help you find an answer to your question?

7 replies

julie.accardo
Klaviyo Employee
Forum|alt.badge.img+36
  • Klaviyo Employee
  • 185 replies
  • August 28, 2021

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 


Forum|alt.badge.img+2
  • Author
  • Contributor IV
  • 9 replies
  • August 30, 2021

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 


Forum|alt.badge.img+2
  • Author
  • Contributor IV
  • 9 replies
  • August 30, 2021

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

 


Forum|alt.badge.img+2
  • Author
  • Contributor IV
  • 9 replies
  • August 30, 2021

@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?


Forum|alt.badge.img+2
  • Author
  • Contributor IV
  • 9 replies
  • August 31, 2021

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


Dov
Forum|alt.badge.img+61
  • Klaviyo Alum
  • 1493 replies
  • September 1, 2021

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 :)


Forum|alt.badge.img+2
  • Author
  • Contributor IV
  • 9 replies
  • September 1, 2021
Pinned reply

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.