diff --git a/scripts/build_trucking_campaigns.py b/scripts/build_trucking_campaigns.py index d459290..4a9e10f 100644 --- a/scripts/build_trucking_campaigns.py +++ b/scripts/build_trucking_campaigns.py @@ -433,8 +433,24 @@ def add_subscriber(list_id: int, email: str, name: str, attribs: dict) -> bool: if status != "enabled": LOG.info("Listmonk suppressed existing subscriber %s status=%s", email, status or "unknown") return False + sub_id = results[0]["id"] + # Refresh attribs so per-campaign merge fields (coupon code, + # ifta_due_date, lp_link, etc.) are correct for THIS send -- + # otherwise a previously-imported carrier keeps stale attribs + # and the new campaign renders blank fields. + try: + merged = dict(results[0].get("attribs") or {}) + merged.update(attribs or {}) + lm_api(f"/subscribers/{sub_id}", { + "email": email, + "name": name or results[0].get("name") or email, + "status": "enabled", + "attribs": merged, + }, "PUT") + except Exception: + pass # non-fatal: still attach to the list below lm_api("/subscribers/lists", { - "ids": [results[0]["id"]], + "ids": [sub_id], "action": "add", "target_list_ids": [list_id], "status": "confirmed",