Skip to content
Advertisement

MailChimp: Why is PUT method with javascript returning “Use PUT to insert or update list members”

I’m trying to update one of my subscriber’s status using mailchimp API 3.0, Meteor and javascript.

Here is my js code I’m using:

request({
  uri,
  list_id,
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'apikey (my api key)'
  },
  json,
}, function(err, res, body) {
  if (err) {
    return console.log("err:", err);
  }
  console.log("connection succeed");
  console.log("res: ", res.body);
  console.log("body: ", body);
});

with

  uri = "https://us15.api.mailchimp.com/3.0/lists/" + (id of my list) + "/members/" + (md5 of my user mail);

and

  json = {
    "email_address": (user mail as a string),
    "status": "unsubscribed"
  };

But I always have the same output:

I20181204-18:42:12.714(8)? title: ‘Member Exists’, I20181204-18:42:12.714(8)? status: 400, I20181204-18:42:12.714(8)? detail: ‘(user mail adress) is already a list member. Use PUT to insert or update list members.’

But I am using PUT already… The request works with POST if it’s the first time I add the user. But now I can’t update my user status… Is something wrong with my request or with the way I use the API? Thanks in advance.

EDIT 1 -> trying with GET doesn’t work. The request itself is correct but it has no effect on my subscriber’s status. So I still need to make PUT work.

Advertisement

Answer

After looking at the official doc in the “Edit” tab, I found the answer!

The json required another mandatory parameter and should look like this:

  json = {
    "email_address":  (user mail as a string),
    "status_if_new": "unsubscribed",
    "status": "unsubscribed"
  };
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement