klaviyo_get_lists
Retrieve all mailing lists from the business's Klaviyo account.
klaviyo_get_lists(context: dict) -> dictRetrieves all mailing lists from the business's Klaviyo account. Useful for letting customers choose which list to subscribe to, or for validating list IDs.
Requires the Klaviyo integration to be installed for the business.
Parameters
| Name | Type | Description |
|---|---|---|
context | dict | The context object passed to your action |
Returns
{"lists": [{"id": "abc123", "name": "Newsletter"}, ...]}Examples
Let a customer pick a mailing list
def execute_action(context):
result = klaviyo_get_lists(context)
return {
"availableLists": [
{"id": l["id"], "name": l["name"]}
for l in result["lists"]
]
}Subscribe to a list by name
def execute_action(context):
email = context["args"]["email"]
list_name = context["args"]["listName"]
result = klaviyo_get_lists(context)
match = next((l for l in result["lists"] if l["name"] == list_name), None)
if match is None:
return {"error": f"List '{list_name}' not found."}
klaviyo_subscribe_to_list(context, email, match["id"])
return {"success": True, "message": f"Subscribed to {list_name}."}