From 2cd556c8199a84de64219de0f8efe197d14db929 Mon Sep 17 00:00:00 2001 From: eugenchio Date: Mon, 20 Jan 2025 13:00:17 +0200 Subject: [PATCH] Update newsletter signup function to add "newsletter" segment to existing contacts --- lambda-functions/newsletter_sign_up.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lambda-functions/newsletter_sign_up.py b/lambda-functions/newsletter_sign_up.py index bc3b1ed..35cc5e8 100755 --- a/lambda-functions/newsletter_sign_up.py +++ b/lambda-functions/newsletter_sign_up.py @@ -32,7 +32,13 @@ def add_crisp_contact(email): website_id=website_id, people_id=email, ) - contact_just_created = True + crisp.website.update_people_profile( + website_id=website_id, + people_id=contact_data['people_id'], + data={ + 'segments': ['newsletter'] + contact_data['segments'], + }, + ) except RouteError: contact_data = crisp.website.add_new_people_profile( website_id=website_id, @@ -42,8 +48,9 @@ def add_crisp_contact(email): 'segments': ['newsletter'], }, ) + contact_just_created = True - if contact_just_created: + if not contact_just_created: subscription_status = crisp.website.get_people_subscription_status( website_id=website_id, people_id=contact_data['people_id'],