Skip to content

Commit 686873b

Browse files
Roller Angeljgzamora
authored andcommitted
I noticed the documentation said a recipients array will replace the … (#185)
I noticed the documentation said a recipients array will replace the current recipients so I wrote this functionality to overcome that as being able to add a single recipient is useful.
1 parent 32d6092 commit 686873b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from sparkpost import SparkPost
2+
3+
4+
# Example list id. Information on getting one is available here:
5+
# https://developers.sparkpost.com/api/recipient-lists/#recipient-lists-post-create-a-recipient-list
6+
list_id = "1234"
7+
8+
# Change this from None to the recipient email that should be added to the recipient list
9+
email = None
10+
11+
sp = SparkPost()
12+
recipient_list = sp.recipient_lists.get(list_id, True)
13+
current_recipients = recipient_list["recipients"]
14+
recipient_values = [recipient["address"] for recipient in current_recipients]
15+
updated_recipients = [
16+
{"address": recipient_value} for recipient_value in recipient_values
17+
]
18+
updated_recipients.append({"address": {"email": email.strip().lower(), "name": ""}})
19+
response = sp.recipient_lists.update(
20+
list_id, name="list name", recipients=updated_recipients
21+
)
22+
print(response)

0 commit comments

Comments
 (0)