AndroidNewb
AndroidNewb

Reputation: 441

MailChimp API 3.0 Invalid Resource Error

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?

Upvotes: 9

Views: 16114

Answers (5)

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;
  });
}

Upvotes: 0

Shahmir
Shahmir

Reputation: 91

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

Upvotes: 0

Yasha Huynh
Yasha Huynh

Reputation: 378

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": {}
}

Upvotes: 13

Dejan Markovic
Dejan Markovic

Reputation: 59

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

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

Upvotes: 2

tamarabyte
tamarabyte

Reputation: 1297

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))

Upvotes: 2

Related Questions