fix: check person exists in CRMs before trying to tag them#99
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent CRM tagging operations from creating or erroring on non-existent people/members by adding existence checks before applying tags in Mailchimp and Action Network.
Changes:
- Mailchimp: skip
addTag/removeTagwhen the member is not found. - Action Network: add
personExists()and skipaddTag/removeTagwhen the person is not found. - Action Network: log the outgoing signup payload.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/join-block/src/Services/MailchimpService.php | Adds a Mailchimp member existence pre-check before tag updates. |
| packages/join-block/src/Services/ActionNetworkService.php | Adds Action Network person existence lookup before tag updates and logs signup payload. |
Comments suppressed due to low confidence (1)
packages/join-block/src/Services/MailchimpService.php:285
- Same as
addTag():removeTag()now does a preflightmemberExists()lookup, adding an extra Mailchimp API call per operation. Consider handling the 404/not-found case in theupdateListMemberTagscatch instead, so you can skip missing members without doubling requests.
if (!self::memberExists($email)) {
$joinBlockLog->warning("Skipping Mailchimp removeTag('$tag') for $email: member does not exist");
return;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ]; | ||
| } | ||
|
|
||
| $joinBlockLog->info("Action Network payload for {$data['email']}: " . json_encode($anData)); |
Comment on lines
+128
to
+132
| ], | ||
| "query" => [ | ||
| "filter" => "email_address eq '" . $email . "'" | ||
| ] | ||
| ] |
Comment on lines
+118
to
+137
| public static function personExists($email) | ||
| { | ||
| $client = new Client(); | ||
|
|
||
| $response = $client->request( | ||
| "GET", | ||
| "https://actionnetwork.org/api/v2/people/", | ||
| [ | ||
| "headers" => [ | ||
| "OSDI-API-Token" => Settings::get("ACTION_NETWORK_API_KEY") | ||
| ], | ||
| "query" => [ | ||
| "filter" => "email_address eq '" . $email . "'" | ||
| ] | ||
| ] | ||
| ); | ||
|
|
||
| $data = json_decode($response->getBody()->getContents(), true); | ||
| return !empty($data["_embedded"]["osdi:people"]); | ||
| } |
Comment on lines
+255
to
+258
| if (!self::memberExists($email)) { | ||
| $joinBlockLog->warning("Skipping Mailchimp addTag('$tag') for $email: member does not exist"); | ||
| return; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.