-
Notifications
You must be signed in to change notification settings - Fork 34
PHP example of adding a member to a list #37
Conversation
php/add-subscriber-to-list.php
Outdated
// Encode data into a format that the add subscriber mailchimp end point is looking for | ||
// Must include 'email_address' and 'status' | ||
// Statuses: pending = they get an email; subscribed = they don't get an email | ||
// Any custom fields go into the weirdly named 'merge_fields' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not so "weirdly" as these are the field names used for merge functionality within templates used by both the Mailchimp admin UI and Mandrill.
Search for "merge_vars":
I encourage you to remove your opinion comments from the PR. Fun to read but perhaps misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed that language and tried to make the comments more readable. Check it out.
And I hear you from an architectural standpoint but think about dev UX here: most API users don't know what your internal architecture looks like. This took me like 45-60 minutes to figure out and I imagine it throws a lot of other people. All your API docs say for merge_field
:
An individual merge var and value for a member.
*/ | ||
$url = 'https://us5.api.mailchimp.com/3.0/lists/' . $list_id . '/members/'; | ||
|
||
/* ================ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, while not a part of the PSR-2 coding standard. It's become typical to structure doc blocks with:
/**
*
*/
References:
*/ | ||
|
||
// Set API Key and list ID to add a subscriber | ||
$api_key = 'your-api-key-here'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using constants as they should not change for the lifetime of the script. Example:
define('API_KEY', 'your-api-key-here');
and access with:
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . API_KEY);
php/add-subscriber-to-list.php
Outdated
// Any custom fields go into the weirdly named 'merge_fields' | ||
// More here: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#create-post_lists_list_id_members | ||
$pfb_data = array( | ||
'apikey' => $apiKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$apiKey
is an invalid variable. It should be:
'apikey' => $api_key,
Felt like closing this big gap in your documentation. I'm sure you guys could make a more canonical example than this but it works and would help many out, judging from what I'm seeing around the net, S.O., blogs, etc.