resubscribe.sh
This commit is contained in:
parent
4b22bab458
commit
f50b0371e3
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
# usage: resubscribe.sh email@example.org
|
||||
|
||||
source credentials.sh
|
||||
|
||||
user="bij1:${MAILCHIMP_API_KEY}"
|
||||
dc='us16'
|
||||
base="https://${dc}.api.mailchimp.com/3.0/"
|
||||
query="$1"
|
||||
list_id='e6beec738b' # leden & geinteresseerden
|
||||
|
||||
# get lists
|
||||
curl -X GET "${base}lists?fields=lists.id,lists.name" --user $user | jq -r '.lists[]'
|
||||
|
||||
# patch email $old to $new in all lists
|
||||
ids=$(curl -X GET "${base}lists?fields=lists.id" --user $user | jq -r '.lists[].id')
|
||||
while IFS= read -r list_id; do
|
||||
echo "list: $list_id"
|
||||
subscriber_url=$(curl -X GET "${base}search-members?list_id=${list_id}&query=${query}&fields=exact_matches.members._links.href" --user $user | jq -r '.exact_matches.members[0]._links[0].href')
|
||||
if [ $subscriber_url != 'null' ]; then
|
||||
echo "✅ found, updating email to $new"
|
||||
curl -X PATCH "$subscriber_url?skip_merge_validation=true" --user $user -d "{\"status\":\"subscribed\"}"
|
||||
else
|
||||
echo "no match"
|
||||
fi
|
||||
done <<< "$ids"
|
Loading…
Reference in New Issue