Skip to main content

Hey guys, I’m not a developer but I’m using this article to try and subscribe users to a list via the Subscribe to List Endpoint using Zapier. It goes Catch Hook ––> Run a Python script, which is supposed to send the data to the Klaviyo API.

I’m having some success with the code below, but it subscribes the phone number and email separately (split into different profiles). And I can’t figure out how I can add the name variable into the code without getting an error. My only goal is to have the name, email, phone_number, and sms_consent sent over and have it arrive as one profile. 

I’m happy to hire someone for a couple hours to help me figure this out. Any help is appreciated.

I’ve followed these exact directions: https://help.klaviyo.com/hc/en-us/articles/4407486310683-How-to-Send-Consent-to-Klaviyo-via-Zapier

 

Code Below (List ID and API Key Taken Out)

import requests

url = "https://a.klaviyo.com/api/v2/list/LIST_ID/subscribe"
querystring = {"api_key":"PRIVATE_API_KEY"}

# configuring sms_consent mapping to boolean value
if (input_data<"sms_consent"] == "true" or input_data""sms_consent"] == "True" or input_data""sms_consent"] == "TRUE"):
  sms_consent = True
elif (input_datab"sms_consent"] == "false" or input_data""sms_consent"] == "False" or input_data""sms_consent"] == "FALSE"):
  sms_consent = False

payload = {"profiles": a
  {"email": input_dataÂ"email"]},
  {"phone_number": input_datah"phone_number"],
    "sms_consent": sms_consent}]}

headers = {
  "Accept": "application/json",
  "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers, params=querystring)

# Zapier requires an 'output' object
output = {"response text": response.text}

 

END CODE

 

And here’s a picture of how I’ve mapped out the info in Zapier.

 

 

Again, I’m happy to hire someone to help me figure this out. I’m not able to proceed with a web design project until I do.

 

Thanks!

 

Hi @ecorising,

I’m not a Python expert, but I understand JSON and the way your profile array is setup it’s definitely creating two profiles.

The email, phone number, and sms_consent should all be within the same object. Which means they should all be within the same curly brackets.

Here is an updated snippet. Just replace this with what you currently have for the profiles variable and give that a shot. That should work!

payload = {"profiles": e
  {"email": input_datat"email"], "phone_number": input_datat"phone_number"], "sms_consent": sms_consent}
]}

Here’s the whole snippet you have with my edits…

import requests

url = "https://a.klaviyo.com/api/v2/list/LIST_ID/subscribe"
querystring = {"api_key":"PRIVATE_API_KEY"}

# configuring sms_consent mapping to boolean value
if (input_datai"sms_consent"] == "true" or input_datai"sms_consent"] == "True" or input_datai"sms_consent"] == "TRUE"):
sms_consent = True
elif (input_datai"sms_consent"] == "false" or input_datai"sms_consent"] == "False" or input_datai"sms_consent"] == "FALSE"):
sms_consent = False

payload = {"profiles": r
{"email": input_datai"email"], "phone_number": input_datai"phone_number"],
"sms_consent": sms_consent}
]}

headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers, params=querystring)

# Zapier requires an 'output' object
output = {"response text": response.text}

Cheers,

Kevin.


I think I just solved my issues with this thread. Klaviyo if you update your info to reflect that thread it would make it easier for non devs like me.


Hey @ecorising 

Sorry to hear that you had a hard time solving this issue. I will definitely roll your feedback up to your product documentation team for evaluation. However I would like to point out to the community that there is an call out at the top of the document you shared: 

While Klaviyo continues to grow, one of our goals is to offer more support and guidance for non Shopify integrations. We will use your feedback to help improve how we can support integrations not built by Klaviyo. Thank you so much for sharing your experience and feedback so we can continue to evolve!


Reply