Skip to content
Snippets Groups Projects
Commit 3725a3fa authored by Alexa Valentová's avatar Alexa Valentová
Browse files

Fix Ecomail newsletter tag updates

parent 6164c134
Branches
No related tags found
2 merge requests!1289Fix Ecomail newsletter tag updates,!1288Fix Ecomail newsletter tag updates
Pipeline #20865 passed
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment