mailerlite API error code 422 for subscribers endpoint

Today, I was implementing the interfacing between and the Mailerlite API (which we use aus our newsletter software).

I got the following error message:

{"error":{"code":422,"message":"Unprocessable entity"}}

The POST request was returning 422 as status code.

Unfortunately there is little documentation about that on Mailerlite. My implementation was correct (this is Crystal Lang by the way):

	get "/test" do |env|
	  body = "{\"email\": \"[email protected]\"}"
	  puts body
      response ="", 
      		headers: HTTP::Headers{
      			"X-MailerLite-ApiKey" => "MAILERLITE_APIKEY",
      			"Content-Type": "application/json"
      		body: body)
  	  if response.status_code != 201 
  	  	puts "newsletter_subscription :: error code #{response.status_code}"
  	  	puts response.body
  	  	puts "newsletter_subscription :: OK"
  	  	puts response.body

where MAILERLITE_APIKEY is the API key which you create in the backend:

(Click on “Generate new token”, it is displayed only once to you).

How to fix 422 when calling the subscribers endpoint of the Mailerlite API

The mailerlite support gave me the solution:

certain email addresses are rejected – e.g. email addresses which are [email protected]<domain>. This is due to the bounce rate being higher on them.

How does a successful response look like?

With a different e-mail address, the response looks like this:

{“id”:2348923942342834,”name”:””,”email”:”[email protected]”,”sent”:0,”opened”:0,”opened_rate”:0,”clicked”:0,”clicked_rate”:0,”type”:”unconfirmed”,”country_id”:””,”signup_ip”:null,”signup_timestamp”:null,”confirmation_ip”:null,”confirmation_timestamp”:null,”fields”:[{“key”:”last_name”,”value”:””,”type”:”TEXT”},{“key”:”company”,”value”:””,”type”:”TEXT”},{“key”:”country”,”value”:””,”type”:”TEXT”},{“key”:”city”,”value”:””,”type”:”TEXT”},{“key”:”phone”,”value”:””,”type”:”TEXT”},{“key”:”state”,”value”:””,”type”:”TEXT”},{“key”:”z_i_p”,”value”:””,”type”:”TEXT”}],”date_subscribe”:”2022-05-19 12:09:24″,”date_unsubscribe”:null,”date_created”:”2022-05-19 12:09:24″,”date_updated”:”2022-05-19 12:09:24″}

The response code is 201, “created”.

Hire us

If you need support for your backend or frontend development, you can hire us. Get in touch for more information.