From 6348198e8e56ff1a24b904dd5f4505e4fc42cfd8 Mon Sep 17 00:00:00 2001 From: Key Date: Mon, 1 Jul 2024 10:45:42 -0500 Subject: [PATCH] add support to add contact to campaign using lists --- target_salesforce_v3/sinks.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/target_salesforce_v3/sinks.py b/target_salesforce_v3/sinks.py index b6d1743..2a15f7c 100644 --- a/target_salesforce_v3/sinks.py +++ b/target_salesforce_v3/sinks.py @@ -117,8 +117,8 @@ def preprocess_record(self, record: dict, context: dict): if record.get('campaigns'): self.campaigns = record['campaigns'] - else: - self.campaigns = None + if not self.campaigns and record.get("lists"): + self.campaigns = [{"name": list_item} for list_item in record.get("lists")] if record.get("addresses"): address = record["addresses"][0] @@ -286,11 +286,9 @@ def assign_to_campaign(self,contact_id,campaigns:list) -> None: id = response.json().get("id") self.logger.info(f"CampaignMember created with id: {id}") - # Check for campaigns to be added - if self.campaigns: - self.assign_to_campaign(id,self.campaigns) except Exception as e: self.logger.exception("Error encountered while creating CampaignMember") + error = f"error: {e}, response: {response.json()}" raise e