MailChimp API 3.0 Invalid Resource Error
Asked Answered
A

5

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":"[email protected]", "status":"subscribed"}

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

Anchovy answered 6/1, 2017 at 15:29 Comment(2)
Having the same exact error message. I've got a support ticket open with them. Hopefully, I can post a resolution here soon.Riverside
I'm having the same issue, any solutions here?Marabelle
L
13

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

{
    "email_address": "[email protected]",
    "status": "subscribed",
    "merge_fields": {}
}
Leukorrhea answered 20/9, 2017 at 0:6 Comment(3)
Thanks! Wish that would be marked as required in the documentation. I suppose setting skip_merge_validation would also do the trick.Genus
@MattCosentino considering I "solved" this 4.5 years ago, it's kinda sad that the docs haven't been updated to account for this.Leukorrhea
"merge_fields" should reflect segments that exist in Audience Members. After I added the missing fields, mine worked.Arielariela
S
2

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

import requests
import json

data = {
  "email_address": "[email protected]",
  "status": "subscribed",
  "merge_fields": {}
}

result = requests.post(<YOUR URL>, auth=<YOUR AUTH CREDS>, data=json.dumps(data))
Subalpine answered 23/3, 2018 at 18:56 Comment(0)
U
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',
Uribe answered 13/7, 2019 at 14:42 Comment(0)
P
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

Penelopa answered 17/1, 2021 at 10:22 Comment(0)
I
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;
  });
}
Inconsiderable answered 23/11, 2021 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.