Skip to content
Snippets Groups Projects

Fix Ecomail newsletter tag updates

Merged Alexa Valentová requested to merge feat/future-calendars into test
1 file
+ 16
4
Compare changes
  • Side-by-side
  • Inline
+ 16
4
@@ -72,11 +72,11 @@ def subscribe_to_newsletter(email, list_id):
def subscribe_to_ecomail_newsletter(
email: str,
categories: str,
tags: str,
source: str,
list_id: int | None = None,
custom_data: dict | None = None,
update_existing: bool = True
update_existing: bool = True,
):
if custom_data is None:
custom_data = {}
@@ -84,13 +84,25 @@ def subscribe_to_ecomail_newsletter(
if not list_id:
list_id = settings.ECOMAIL_DEFAULT_LIST_ID
split_categories = categories.split(",") if categories is not None else []
existing_subscriber_data = requests.get(
urljoin(settings.ECOMAIL_API_URL, f"lists/{list_id}/subscriber/{email}"),
headers={"key": settings.ECOMAIL_API_KEY},
)
existing_tags = []
if existing_subscriber_data.status_code == 200:
existing_subscriber_data = existing_subscriber_data.json()
existing_tags = existing_subscriber_data["subscriber"]["tags"]
split_tags = tags.split(",") if tags is not None else []
split_tags += existing_tags
data = {
"subscriber_data": {
"email": email,
"source": source,
"tags": split_categories,
"tags": split_tags,
**custom_data,
},
"update_existing": update_existing,
Loading