mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM
https://dev.mailjet.com
Other
130 stars 72 forks source link

How to use Send API v3.1 and REST API v3 at the same time? #246

Closed Spone closed 1 year ago

Spone commented 1 year ago

In our app, we need to send emails using the v3.1 Send API, and sync data (contact lists) using the REST v3 API. How to use both, given that we can only have one Mailjet.configure call?

Is it possible to override the API version on a per-request basis?

mgrishko commented 1 year ago

@Spone Yes, you can use a specific version when sending a request. For example:

Mailjet::Send.create({
        messages: [{
          'From' => {
            'Email' => "pilot@example.com",
            'Name' => 'Mailjet Ruby Wrapper CI'
          },
          'To' => [
            recipient
          ],
            'Subject' => 'Mailjet Ruby Wrapper CI Send API v3.1 spec',
            'TextPart' => 'Mailjet Ruby Wrapper CI content',
            'HTMLPart' => 'HTML Mailjet Ruby Wrapper CI content'
          }]
        },
        version: 'v3.1'
      )

or change version before sending request

 Mailjet.config.api_version = 'v3.1'
....

Is this answer helpful to you?