8

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.

Virthuss
  • 3,142
  • 1
  • 21
  • 39

2 Answers2

7

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"
  };
zeusstl
  • 1,673
  • 18
  • 19
Virthuss
  • 3,142
  • 1
  • 21
  • 39
2

I know that this is an older question but I just wanted to add something in the event that it helps someone. I was having a similar issue intermittently with most of my PUT requests working as expected and some not. It took me a while but eventually I figured out that some of my email addresses had spaces at the end. This error would result. Trimming the addresses before doing anything resolved my issue.

O Genthe
  • 161
  • 9