Skip to content

Delete Requests

John Hutcheson edited this page Aug 26, 2018 · 1 revision

Delete Requests

Delete requests are made (as the name might suggest) when we want to remove a record from MailChimp. They can be made through this library using the delete() method on any ApiResource instance. Let say we want to Remove the subscriber we added while reviewing the post() method.

You can review POST requests here: https://github.com/Jhut89/Mailchimp-API-3.0-PHP/wiki/Post-Requests

If you recall the response we got when we posted our list member looked like:

{
  "id": "852aaa9532cb36adfb5e9fef7a4206a9",
  "email_address": "[email protected]",
  "unique_email_id": "fab20fa03d",
  "email_type": "html",
  "status": "subscribed",
  "status_if_new": "",
  "merge_fields": {
    "FNAME": "",
    "LNAME": ""
  },
  "interests": {
    "9143cf3bd1": false,
    "3a2a927344": false,
    "f9c8f5f0ff": false,
    "f231b09abc": false,
    "bd6e66465f": false
  },
  "stats": {
    "avg_open_rate": 0,
    "avg_click_rate": 0
  },
  "ip_signup": "",
  "timestamp_signup": "",
  "ip_opt": "198.2.191.34",
  "timestamp_opt": "2015-09-16 19:24:29",
  "member_rating": 2,
  "last_changed": "2015-09-16 19:24:29",
  "language": "",
  "vip": false,
  "email_client": "",
  "location": {
    "latitude": 0,
    "longitude": 0,
    "gmtoff": 0,
    "dstoff": 0,
    "country_code": "",
    "timezone": ""
  },
  "list_id": "57afe96172",
  "_links": [...]
}

Removing them from MailChimp can be done using the delete() method like this:

$delete_response = $mailchimp
                       ->lists("57afe96172")
                       ->members("[email protected]")
                       ->delete();

Again we notice that we can provide an email address directly to the members() method as this library will translate this to a member_id. As well we can see that the delete() method does not take in any arguments. Calling the delete() method on this instance should send back the following response according to the MailChimp API documentation:

HTTP/1.1 204 No Content
Server: nginx
Content-Type: application/json; charset=utf-8
Content-Length: 2
X-Request-Id: 0e71b16c-d99f-4651-b2e5-ea39747f44e0
Date: Wed, 16 Sep 2015 20:29:37 GMT
Connection: keep-alive

Because the response has an HTTP response code within the 200 range $delete_response->wasSuccess() will return true.

Clone this wiki locally