Mailerlite is not found on Heroku
I'm using the 'mailerlite' gem on my rails 7 application, and for every new user signing up to my webapp, I add them to a simple welcome email workflow. Here's my current setup. Code inside config/initializers/mailerlite.rb
MailerLite.configure do |config|
config.api_key = ENV['MAILERLITE_API_KEY']
# config.timeout = 10
end
Here's how I use it inside my methods.
mailer_lite_client = MailerLite::Client.new
# Add to mailerlite artists group subscriber = { email: user.email, name: user.first_name }
unless mailer_lite_client.subscriber(user.email)
mailer_lite_client.create_subscriber(subscriber)
end
mailer_lite_client.create_group_subscriber(groupid, subscriber)
This setup works well on my dev box. On production, Heroku, I'm getting null errors. Would you happen to know if I'm missing something. Thank you, Ritesh
Hello @miyakisynth ,
Can you make sure gem is in correct group in Gemfile (not in group :development)
Thanks Justas. Yes, It's not in the :development group. I checked that the server has 1.16.1 installed, when i do a bundle list. However, I get a Mailerlite not found error.
Does adding require 'mailerlite' to config/initializers/mailerlite.rb helps ?
My local code stopped working now too :(
I'm getting this error now. When I debug, I see the mailerlite client is created, the apikey is loaded. Unfortunately, the first call goes this way.
Completed 500 Internal Server Error in 71743ms (ActiveRecord: 0.4ms | Allocations: 53376) MailerLite::Unauthorized (Unauthorized):
I'm too scared to add this to the critical path on server yet, so I have not been able to test out having require 'mailerlite' to the initializer file. Once I can get this running locally, I'll test out the server side change too.
I put it on the critical path to test, and I can confirm that it's reproducible.
2025-02-13T00:07:33.148317+00:00 app[web.1]: I, [2025-02-13T00:07:33.148268 #2] INFO -- : [d622560b-2fcd-4aab-b603-1004ef58484b] Completed 500 Internal Server Error in 5966ms (ActiveRecord: 56.1ms | Allocations: 16625)
2025-02-13T00:07:33.148750+00:00 app[web.1]: F, [2025-02-13T00:07:33.148724 #2] FATAL -- : [d622560b-2fcd-4aab-b603-1004ef58484b]
2025-02-13T00:07:33.148750+00:00 app[web.1]: [d622560b-2fcd-4aab-b603-1004ef58484b] MailerLite::NotFound (Not found):
Heroku logs just say "MailerLite::NotFound"
Heroku support got back to me with the following response.
Thanks for reaching out to Heroku support.
We initially thought the issue might be that the MailerLite gem, which you added to your Gemfile, hadn't been committed to your remote repository. But, upon inspecting your Gemfile.lock, we found that the gem is indeed included.
mailerlite (1.16.1) faraday (~> 2.0, >= 2.0.1) faraday-follow_redirects (~> 0.3) faraday-mashify (~> 0.1) hashie (>= 4, < 6)
They claim the bug is in my code, not with the Heroku box or the configuration. I'm going to focus on solving my local issues first before trying to debug what's wrong with the deployed setup.