9

I am simply trying to add a new member to a MailChimp list. But I keep getting the following error and can't quite understand why:

type: http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
title: Invalid Resource
status: 400
detail: The resource submitted could not be validated. For field-specific details, see the 'errors' array.
instance:
errors:
0:
field:
message: Schema describes object, NULL found instead

This is quite odd because I am sending the exact object in the body as detailed in the exampled from the docs:

{"email_address":"urist.mcvankab+3@freddiesjokes.com", "status":"subscribed"}

I have tried the call in Postman as well the MailChimp Playground. Am I omitting something in the JSON here?

AndroidNewb
  • 441
  • 3
  • 6
  • 14

5 Answers5

13

So I was stuck as well, turns out you need to have "merge_fields". Make it an empty object,

{
    "email_address": "blahblar@blarblah.com",
    "status": "subscribed",
    "merge_fields": {}
}
Yasha Huynh
  • 378
  • 3
  • 9
  • 1
    Thanks! Wish that would be marked as required in the documentation. I suppose setting skip_merge_validation would also do the trick. – Matt Cosentino Apr 08 '21 at 15:23
  • 2
    @MattCosentino considering I "solved" this 4.5 years ago, it's kinda sad that the docs haven't been updated to account for this. – Yasha Huynh Jan 31 '22 at 20:21
  • "merge_fields" should reflect segments that exist in Audience Members. After I added the missing fields, mine worked. – nywooz Dec 19 '22 at 18:55
2

Make sure you encode your post data as json. For example in python:

import requests
import json

data = {
  "email_address": "test_email@gmail.com",
  "status": "subscribed",
  "merge_fields": {}
}

result = requests.post(<YOUR URL>, auth=<YOUR AUTH CREDS>, data=json.dumps(data))
tamarabyte
  • 1,144
  • 13
  • 19
2

The problem is in url. You must have members on the url end:

  url: 'https://blabla.api.mailchimp.com/3.0/lists/blabla/members',
0

i was working with node application and this worked for me, instead of using

 url: 'https://blabla.api.mailchimp.com/3.0/lists/{list_id}/members'

try this JavaScript object:

const data = {
members:[{
email_address: email,
  status: "subscribed",
  merge_fields: {
    FNAME : firstName,
    LNAME : lastName  }
  }]
};

and use url:

url: "https://us7.api.mailchimp.com/3.0/lists/{list_id}"

Note: you must convert JavaScript object to JSON

Shahmir
  • 31
  • 6
0

Even if the merge_fields aren't marked as required they are, to bypass the requirement you can pass the query parameter { skipMergeValidation: true } as the third parameter in the addListMember request. You can see the doc and the implementation below:

  • Add a new member to the list.
  • @param {String} listId The unique ID for the list.
  • @param {module:model/AddListMembers1} body
  • @param {Object} opts Optional parameters
  • @param {Boolean} opts.skipMergeValidation If skip_merge_validation is true, member data will be accepted without merge field values, even if the merge field is usually required. This defaults to false.
  • @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/ListMembers2}
this.addListMember = function(listId, body, opts) {
  return this.addListMemberWithHttpInfo(listId, body, opts)
    .then(function(response_and_data) {
      return response_and_data.data;
  });
}