Skip to content

Instantly share code, notes, and snippets.

@tforster
Last active July 25, 2023 08:21
Show Gist options
  • Save tforster/f6b516479381519cdf8a5b392a78bbe5 to your computer and use it in GitHub Desktop.
Save tforster/f6b516479381519cdf8a5b392a78bbe5 to your computer and use it in GitHub Desktop.
MailChimp PostMan Collection
{
"info": {
"_postman_id": "e5d286ab-6f35-46dd-a9f0-9c3c55b5db18",
"name": "MailChimp",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get lists info",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{dc}}.api.mailchimp.com/3.0/lists",
"protocol": "https",
"host": [
"{{dc}}",
"api",
"mailchimp",
"com"
],
"path": [
"3.0",
"lists"
],
"query": [
{
"key": "fields",
"value": "",
"disabled": true
},
{
"key": "exclude_fields",
"value": "",
"disabled": true
},
{
"key": "count",
"value": "10",
"disabled": true
},
{
"key": "offset",
"value": "0",
"disabled": true
},
{
"key": "before_date_created",
"value": "",
"disabled": true
},
{
"key": "since_date_created",
"value": "",
"disabled": true
},
{
"key": "before_campaign_last_sent",
"value": "",
"disabled": true
},
{
"key": "since_campaign_last_sent",
"value": "",
"disabled": true
},
{
"key": "email",
"value": "",
"disabled": true
},
{
"key": "sort_field",
"value": "",
"disabled": true
},
{
"key": "sort_dir",
"value": "",
"disabled": true
},
{
"key": "has_ecommerce_store",
"value": "",
"disabled": true
},
{
"key": "include_total_contacts",
"value": "",
"disabled": true
}
]
},
"description": "[https://mailchimp.com/developer/marketing/api/list-members/](https://mailchimp.com/developer/marketing/api/list-members/)"
},
"response": []
},
{
"name": "Add or update a list member",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"// Reconstruct the path by manually parsing PM environment variables AND MD5 hashing the inline email address\r",
"const path = pm.request.url.path\r",
" .reduce((prev, pathString) => {\r",
" // Check to see if pathString is wrapped in {{}} and therefore a PostMan environment variable\r",
" const matches = pathString.match(/{{(\\w*||[\\w\\d.-]*@[\\w\\d.]*)}}/);\r",
" if (matches && matches.length === 2) {\r",
" pmEnv = pm.environment.get(matches[1]);\r",
" if (pmEnv) {\r",
" prev.push(pmEnv);\r",
" } else {\r",
" // Replace the clear text email address with an MD5 hash (MailChimp calls this the subscriber_hash)\r",
" const md5 = matches[1].replace(/[\\w\\d.-]*@[\\w\\d.]*/, (match, $1) =>\r",
" CryptoJS.MD5(match).toString()\r",
" );\r",
" prev.push(md5);\r",
" }\r",
" } else {\r",
" prev.push(pathString);\r",
" }\r",
" return prev;\r",
" }, [])\r",
" .join(\"/\");\r",
"\r",
"pm.request.url = `https://${pm.environment.get(\"dc\")}.api.mailchimp.com/${path}${pm.request.url.query}`;"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"email_address\": \"\",\r\n \"status_if_new\": \"subscribed\",\r\n \"email_type\": \"\",\r\n \"status\": \"subscribed\",\r\n \"merge_fields\": {},\r\n \"interests\": {},\r\n \"language\": \"\",\r\n \"vip\": false,\r\n \"location\": {\r\n \"latitude\": 0,\r\n \"longitude\": 0\r\n },\r\n \"marketing_permissions\": [],\r\n \"ip_signup\": \"\",\r\n \"timestamp_signup\": \"\",\r\n \"ip_opt\": \"\",\r\n \"timestamp_opt\": \"\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{dc}}.api.mailchimp.com/3.0/lists/{{listId}}/members/{{troy.forster@gmail.com}}?email_address=troy.forster@gmail.com&status_if_new=subscribed",
"protocol": "https",
"host": [
"{{dc}}",
"api",
"mailchimp",
"com"
],
"path": [
"3.0",
"lists",
"{{listId}}",
"members",
"{{troy.forster@gmail.com}}"
],
"query": [
{
"key": "skip_merge_validation",
"value": "true",
"disabled": true
},
{
"key": "email_address",
"value": "troy.forster@gmail.com",
"description": "The email address is required if this is an \"add\" operation"
},
{
"key": "status_if_new",
"value": "subscribed",
"description": "The status is required if this is an \"add\" operation"
}
]
},
"description": "[https://mailchimp.com/developer/marketing/api/list-members/add-or-update-list-member/](https://mailchimp.com/developer/marketing/api/list-members/add-or-update-list-member/)"
},
"response": []
},
{
"name": "List members info",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{dc}}.api.mailchimp.com/3.0/lists/{{listId}}/members",
"protocol": "https",
"host": [
"{{dc}}",
"api",
"mailchimp",
"com"
],
"path": [
"3.0",
"lists",
"{{listId}}",
"members"
],
"query": [
{
"key": "fields",
"value": "",
"disabled": true
},
{
"key": "exclude_fields",
"value": "",
"disabled": true
},
{
"key": "count",
"value": "10",
"disabled": true
},
{
"key": "offset",
"value": "0",
"disabled": true
},
{
"key": "email_type",
"value": "",
"disabled": true
},
{
"key": "status",
"value": "",
"disabled": true
},
{
"key": "since_timestamp_opt",
"value": "",
"disabled": true
},
{
"key": "before_timestamp_opt",
"value": "",
"disabled": true
},
{
"key": "since_last_changed",
"value": "",
"disabled": true
},
{
"key": "before_last_changed",
"value": "",
"disabled": true
},
{
"key": "unique_email_id",
"value": "",
"disabled": true
},
{
"key": "vip_only",
"value": "",
"disabled": true
},
{
"key": "interest_category_id",
"value": "",
"disabled": true
},
{
"key": "interest_ids",
"value": "",
"disabled": true
},
{
"key": "interest_match",
"value": "",
"disabled": true
},
{
"key": "sort_field",
"value": "",
"disabled": true
},
{
"key": "sort_dir",
"value": "",
"disabled": true
},
{
"key": "since_last_campaign",
"value": "",
"disabled": true
},
{
"key": "unsubscribed_since",
"value": "",
"disabled": true
}
]
},
"description": "[https://mailchimp.com/developer/marketing/api/list-members/list-members-info/](https://mailchimp.com/developer/marketing/api/list-members/list-members-info/)"
},
"response": []
},
{
"name": "Delete list member",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"// Reconstruct the path by manually parsing PM environment variables AND MD5 hashing the inline email address\r",
"const path = pm.request.url.path\r",
" .reduce((prev, pathString) => {\r",
" // Check to see if pathString is wrapped in {{}} and therefore a PostMan environment variable\r",
" const matches = pathString.match(/{{(\\w*||[\\w\\d.-]*@[\\w\\d.]*)}}/);\r",
" if (matches && matches.length === 2) {\r",
" pmEnv = pm.environment.get(matches[1]);\r",
" if (pmEnv) {\r",
" prev.push(pmEnv);\r",
" } else {\r",
" // Replace the clear text email address with an MD5 hash (MailChimp calls this the subscriber_hash)\r",
" const md5 = matches[1].replace(/[\\w\\d.-]*@[\\w\\d.]*/, (match, $1) =>\r",
" CryptoJS.MD5(match).toString()\r",
" );\r",
" prev.push(md5);\r",
" }\r",
" } else {\r",
" prev.push(pathString);\r",
" }\r",
" return prev;\r",
" }, [])\r",
" .join(\"/\");\r",
"\r",
"pm.request.url = `https://${pm.environment.get(\"dc\")}.api.mailchimp.com/${path}`;"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"url": {
"raw": "https://{{dc}}.api.mailchimp.com/3.0/lists/{{listId}}/members/{{troy.forster@gmail.com}}/actions/delete-permanent",
"protocol": "https",
"host": [
"{{dc}}",
"api",
"mailchimp",
"com"
],
"path": [
"3.0",
"lists",
"{{listId}}",
"members",
"{{troy.forster@gmail.com}}",
"actions",
"delete-permanent"
]
},
"description": "[https://mailchimp.com/developer/marketing/api/list-members/delete-list-member/](https://mailchimp.com/developer/marketing/api/list-members/delete-list-member/)"
},
"response": []
}
],
"auth": {
"type": "apikey",
"apikey": [
{
"key": "value",
"value": "{{basicAuth}}",
"type": "string"
},
{
"key": "key",
"value": "Authorization",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"// The MailChimp API requires basic auth credentials where the username is \"anystring\" and password is the API key",
"const basicAuth = \"Basic \" + Buffer.from(`anystring:${pm.environment.get('apiKey')}`).toString(\"base64\") ;",
"pm.environment.set('basicAuth', basicAuth);"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
{
"_postman_exported_at": "2021-12-16T16:39:05.645Z",
"_postman_exported_using": "Postman/9.4.0",
"_postman_variable_scope": "environment",
"id": "de38ff31-d9d0-4ca0-8b00-75e64d47394d",
"name": "MailChimp",
"values": [
{
"enabled": true,
"key": "dc",
"value": "<YOUR DC>"
},
{
"enabled": true,
"key": "apiKey",
"value": "<YOUR API KEY>"
},
{
"enabled": true,
"key": "basicAuth",
"value": "<AUTO GENERATED>"
},
{
"enabled": true,
"key": "listId",
"value": "<A VALID LIST ID>"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment