mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM

Home Page:https://dev.mailjet.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Api v3.0 vs api v3.1

sluceno opened this issue · comments

We've always been using mailjet without configuring version, so I assume we use v3.0

We've been using mailjet to push users to a contact list after signup.

Mailjet::Contact.create(email: "foo", name: "bar")

Now, we started to send emails through the api, and we decided to use the version 3.1 as it was the latest, so we configured version v3.1.

Sending emails was working great, but suddenly, after the changing to v3.1 we could not create more Contacts. The api always returns a 404 when doing Mailjet::Contact.create(email: "foo", name: "bar")

What does this mean? v3.1 does not support any stuff from 3.0?

How should I use the Gem then? Because we want to keep creating contacts and send emails at the same time.

I would have expected the v3.1 to support all the functionality from Mailjet as every library does when bumping a new version.

Hey @sluceno

I ran into the same issue. I wanted to send emails with version 3.1 since its templating feature is more convenient. After I switched to 3.1 all contact related API calls returned a 404. It seems that version 3.1 is not backwards compatible - even more it seems they are completely different and serve different purposes.

Searching the internet for a solution I found this:

# config/initializers/mailjet.rb
Mailjet.configure do |config|
  config.api_key = ENV.fetch('MAILJET_API_KEY')
  config.secret_key = ENV.fetch('MAILJET_SECRET_KEY')
  config.default_from = 'example@example.com'
  config.api_version = 'v3'
end

module Mailjet
  # A wrapper for version 3.1.
  class Send31
    include Mailjet::Resource

    self.version = 'v3.1'
    self.resource_path = 'send'
    self.public_operations = [:post]
  end
end

And then in my code that sends out the emails I can use:

Mailjet::Send31.create(...)

That's not the best solution - but it works quite good.

Hey @henvo

Thanks for your answer, we ended up refactoring everything to use 3.0 since we realised at that moment we could pass without 3.1 features on sending emails.

If we need to work with 3.1 definitely we will do as you mentioned. Thanks a lot!