### Usage Example: Getting Account Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/users_api.md Shows how to retrieve and display key account details such as public ID, reputation, and hourly quota using the `info` method. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') info = client.users.info() puts "Account public ID: #{info['public_id']}" puts "Account reputation: #{info['reputation']}" puts "Hourly quota: #{info['hourly_quota']}" ``` -------------------------------- ### Basic Export Workflow Example Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/exports_api.md Demonstrates a complete workflow for starting an activity export, monitoring its status until completion or error, and retrieving the download URL. Includes a timeout mechanism. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') # Step 1: Start export puts "Starting activity export..." export = client.exports.activity() export_id = export['id'] puts "Export ID: #{export_id}" puts "Initial status: #{export['state']}" # Step 2: Wait for completion puts "Waiting for export to complete..." max_wait = 300 # 5 minutes start_time = Time.now loop do status = client.exports.info({ id: export_id }) puts "Status: #{status['state']}" if status['state'] == 'complete' puts "Export complete!" puts "Download URL: #{status['result_url']}" break elsif status['state'] == 'error' puts "Export failed!" break elsif Time.now - start_time > max_wait puts "Export timed out" break else sleep(10) end end ``` -------------------------------- ### Basic Setup and Connection Test Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/configuration.md Demonstrates a basic client setup using an API key (retrieved from an environment variable or a fallback) and includes a test to verify the connection by pinging the users API. ```ruby require 'MailchimpTransactional' api_key = ENV['MANDRILL_API_KEY'] || 'your_api_key' client = MailchimpTransactional::Client.new(api_key) # Test the connection begin response = client.users.ping() puts "Connected successfully" rescue MailchimpTransactional::ApiError => e puts "Connection failed: #{e.message}" end ``` -------------------------------- ### Development Setup with Local Testing Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/configuration.md Provides a setup for development environments, allowing skipping API configuration if a specific environment variable is set, useful for local testing. ```ruby require 'MailchimpTransactional' # Use test API key or skip initialization if ENV['SKIP_API_TESTS'] puts "Skipping API configuration for testing" else client = MailchimpTransactional::Client.new(ENV['MANDRILL_API_KEY']) end ``` -------------------------------- ### ips.start_warmup Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/README.md Starts the IP warmup process for a specific IP address. ```APIDOC ## POST /ips/start-warmup ### Description Starts the IP warmup process for a specific IP address. ### Method POST ### Endpoint /ips/start-warmup ### Parameters #### Request Body - **ip** (string) - Required - The IP address to start warmup for. ``` -------------------------------- ### Install Local Ruby Gem Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/README.md Installs a locally built Ruby gem. Use the --dev flag to include development dependencies. ```shell gem install ./MailchimpTransactional-1.4.1.gem ``` ```shell gem install --dev ./MailchimpTransactional-1.4.1.gem ``` -------------------------------- ### Common Webhook Management Patterns Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Provides examples for managing webhooks, including listing, adding, retrieving info, updating, and deleting webhooks. ```ruby client.webhooks.list() client.webhooks.add(webhook_hash) client.webhooks.info(id_hash) client.webhooks.update(update_hash) client.webhooks.delete(id_hash) ``` -------------------------------- ### Start Exports Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/exports_api.md Initiates new exports for specified types such as 'activity', 'allowlist', or 'rejects'. This method starts the export process and returns the ID of the newly created export job. ```APIDOC ## Start Exports ### Description Initiates new exports for specified types such as 'activity', 'allowlist', or 'rejects'. This method starts the export process and returns the ID of the newly created export job. ### Method POST ### Endpoint /exports/{type} ### Parameters #### Path Parameters - **type** (string) - Required - The type of export to start (e.g., 'activity', 'allowlist', 'rejects'). ### Response #### Success Response (200) - **id** (string) - The unique identifier for the newly created export job. ### Response Example ```json { "id": "new_export_id_456" } ``` ``` -------------------------------- ### Start IP Warmup Process Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/ips_api.md Initiates the warmup process for a new dedicated IP address. This gradually increases sending volume to build reputation. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') # Start warmup for new IP ip = '192.0.2.100' response = client.ips.start_warmup({ ip: ip }) puts "Starting warmup for #{ip}" puts "Warmup Status: #{response['warmup_status']}" ``` -------------------------------- ### Usage Example: Validating API Key Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/users_api.md Demonstrates how to initialize the client and use the `ping` method to validate an API key, including error handling for API errors. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') begin response = client.users.ping() puts "API key is valid: #{response}" rescue MailchimpTransactional::ApiError => e puts "API key validation failed: #{e.message}" end ``` -------------------------------- ### Ruby Webhook Handler Example Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/webhooks_api.md This example demonstrates how to set up a Sinatra application to receive and process incoming webhook events from Mailchimp. It parses the JSON payload and handles different event types. ```ruby require 'sinatra' require 'json' post '/webhooks/mandrill' do # Get the raw JSON payload payload = JSON.parse(params[:mandrill_events]) payload.each do |event_data| case event_data['type'] when 'send' puts "Message sent to: #{event_data['msg']['to'].first['email']}" when 'open' puts "Message opened by: #{event_data['msg']['to'].first['email']}" when 'click' puts "Link clicked in message: #{event_data['msg']['subject']}" when 'bounce' puts "Message bounced: #{event_data['msg']['bounce_description']}" when 'spam' puts "Message marked as spam: #{event_data['msg']['to'].first['email']}" when 'unsub' puts "Unsubscribe: #{event_data['msg']['to'].first['email']}" end end 'ok' end ``` -------------------------------- ### Initialize Mailchimp Transactional Client Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/client.md Instantiate the Mailchimp Transactional client with your API key. Ensure you have the 'MailchimpTransactional' gem installed. ```ruby MailchimpTransactional::Client.new('your_api_key_here') ``` -------------------------------- ### Build Ruby Gem Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/README.md Builds the Ruby code into a gem package. This is the first step before installing or publishing the gem. ```shell gem build MailchimpTransactional.gemspec ``` -------------------------------- ### Usage Example: Retrieving Senders Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/users_api.md Illustrates how to fetch a list of senders and iterate through them to display their addresses and verification status. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') senders = client.users.senders() puts "Total senders: #{senders.length}" senders.each do |sender| status = sender['verified'] ? 'Verified' : 'Unverified' puts "#{sender['address']} (#{status})" end ``` -------------------------------- ### Start IP Warmup Process Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/ips_api.md Initiate the warmup process for a dedicated IP address. This gradually increases sending volume over approximately 30 days to build reputation. Requires the IP address in the request body. ```ruby client = MailchimpTransactional::Client.new('your_api_key') response = client.ips.start_warmup({ ip: '192.0.2.1' }) puts "Started warmup for #{response['ip']}" puts "Warmup Status: #{response['warmup_status']}" ``` -------------------------------- ### Start IP Warmup Process Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/ips_api.md Initiates the warmup process for a dedicated IP address, gradually increasing email volume over approximately 30 days. ```APIDOC ## POST /ips/start-warmup ### Description Begins the warmup process for a dedicated IP. Gradually increases email volume over approximately 30 days. ### Method POST ### Endpoint /ips/start-warmup ### Parameters #### Query Parameters - **body** (Hash) - Required - Request body containing IP address - **ip** (String) - Required - IP address to warm up ### Request Example ```ruby client = MailchimpTransactional::Client.new('your_api_key') response = client.ips.start_warmup({ ip: '192.0.2.1' }) puts "Started warmup for #{response['ip']}" puts "Warmup Status: #{response['warmup_status']}" ``` ### Response #### Success Response (200) - **Hash** - Updated IP object with warmup status. #### Response Example ```json { "ip": "192.0.2.1", "pool": "general", "status": "active", "reputation": 85, "warmup_status": true } ``` ``` -------------------------------- ### Configure Custom Reverse DNS for Dedicated IP Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/ips_api.md A workflow example demonstrating how to first validate a domain for custom reverse DNS and then set it for a dedicated IP. This ensures the domain is correctly configured before assignment. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') ip = '192.0.2.1' domain = 'mail.example.com' # Validate domain first validation = client.ips.check_custom_dns({ ip: ip, domain: domain }) if validation['valid'] # Set the custom DNS result = client.ips.set_custom_dns({ ip: ip, domain: domain }) puts "Set custom DNS: #{result['domain']}" else puts "Domain validation failed" end ``` -------------------------------- ### Basic Mailchimp Transactional Client Setup Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/client.md Initialize the Mailchimp Transactional client with your API key and test the connection using the users.ping method. Includes basic error handling for API errors. ```ruby require 'MailchimpTransactional' begin client = MailchimpTransactional::Client.new('your_api_key') # Test the API connection response = client.users.ping() puts "API Connection successful: #{response}" rescue MailchimpTransactional::ApiError => e puts "API Error: #{e.message}" end ``` -------------------------------- ### Common Template Management Patterns Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Provides examples for managing email templates, including listing, adding, retrieving info, updating, publishing, deleting, rendering, and viewing time series data. ```ruby client.templates.list() client.templates.add(template_hash) client.templates.info(name_hash) client.templates.update(update_hash) client.templates.publish(name_hash) client.templates.delete(name_hash) client.templates.render(render_hash) client.templates.time_series(name_hash) ``` -------------------------------- ### Access IPs API Module Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/client.md Manage dedicated IPs and IP pools through the IPs API. This example demonstrates how to list available IP addresses. ```ruby client.ips.list() ``` -------------------------------- ### Access Exports API Module Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/client.md Use the Exports API to manage data exports. This example demonstrates how to list available exports. ```ruby client.exports.list() ``` -------------------------------- ### Start Allowlist Export Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/exports_api.md Begin an export of the account's allowlist. The response includes the export job ID and initial status, with the data downloadable once complete. ```ruby client = MailchimpTransactional::Client.new('your_api_key') export_job = client.exports.allowlist() puts "Started allowlist export: #{export_job['id']}" ``` -------------------------------- ### Access Allowlists API Module Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/client.md Interact with the Allowlists API to manage email allowlists. This example shows how to add an email to the allowlist. ```ruby client.allowlists.add(email: 'test@example.com') ``` -------------------------------- ### Send a Message Using a Template Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/messages_api.md This example shows how to send an email using a pre-defined template. You need to specify the template name, any dynamic content to be inserted into the template, and the basic message details. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') response = client.messages.send_template({ template_name: 'welcome-template', template_content: [ { name: 'user_name', content: 'John' }, { name: 'activation_link', content: 'https://example.com/activate' } ], message: { from_email: 'noreply@example.com', to: [{ email: 'john@example.com' }] } }) ``` -------------------------------- ### Start Rejects (Denylist) Export Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/exports_api.md Initiate an export of the account's rejection list (denylist). The method returns an export job ID and status, allowing you to track its completion. ```ruby client = MailchimpTransactional::Client.new('your_api_key') export_job = client.exports.rejects() export_id = export_job['id'] ``` -------------------------------- ### Check Custom DNS Settings for IP Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Test the custom DNS configuration for a dedicated IP address using the `ips.check_custom_dns` method. This helps ensure proper deliverability setup. ```ruby client.ips.check_custom_dns(ip: '192.168.1.1') ``` -------------------------------- ### Initiate Allowlist Export Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/exports_api.md Starts an export of the account's allowlist. This is an alias for the `allowlist` method. The method returns an export job object containing an ID and initial status. ```ruby client = MailchimpTransactional::Client.new('your_api_key') # These two calls are equivalent export1 = client.exports.allowlist() export2 = client.exports.whitelist() ``` -------------------------------- ### Basic Error Handling with Mailchimp Transactional Client Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/errors.md A fundamental example of setting up the Mailchimp Transactional client and using a begin-rescue block to catch and report any ApiError during an API call. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') begin response = client.users.ping() puts "API connection successful" rescue MailchimpTransactional::ApiError => e puts "API Error: #{e.message}" exit 1 end ``` -------------------------------- ### Update Webhook Configuration with New Events Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/webhooks_api.md This example demonstrates how to update an existing webhook by adding new events to its subscription list. It first retrieves the current webhook details, modifies the events array, and then applies the update. ```Ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') # Get existing webhook webhook = client.webhooks.info({ id: 123 }) # Add new events new_events = webhook['events'] + ['inbound'] new_events = new_events.uniq # Update webhook response = client.webhooks.update({ id: 123, events: new_events, description: 'Updated to include inbound events' }) puts "Updated webhook with #{response['events'].length} events" ``` -------------------------------- ### Get Template Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/templates_api.md Retrieves detailed information about an existing template by its name. Use this to get template metadata and statistics. ```ruby client = MailchimpTransactional::Client.new('your_api_key') template = client.templates.info({ name: 'welcome-email' }) puts "Template: #{template['name']}" puts "Last updated: #{template['updated_at']}" puts "From: #{template['from_email']}" ``` -------------------------------- ### Rails Integration for Mailchimp Client Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Provides an example of how to configure the Mailchimp Transactional client within a Rails application's initializers. Sets timeout and default output format. ```ruby # config/initializers/mailchimp_transactional.rb MAILCHIMP_CLIENT = MailchimpTransactional::Client.new( ENV['MAILCHIMP_TRANSACTIONAL_API_KEY'] ) MAILCHIMP_CLIENT.set_timeout(300) MAILCHIMP_CLIENT.set_default_output_format('json') ``` -------------------------------- ### Initialize Client with API Key Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Shows how to initialize the Mailchimp Transactional client using an API key fetched from an environment variable. Includes optional configuration for timeout and output format. ```ruby require 'MailchimpTransactional' api_key = ENV.fetch('MAILCHIMP_TRANSACTIONAL_API_KEY') client = MailchimpTransactional::Client.new(api_key) # Configure based on environment if ENV['RAILS_ENV'] == 'production' client.set_timeout(300) client.set_default_output_format('json') end ``` -------------------------------- ### Send Simple and Templated Emails Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Demonstrates how to send a basic email and an email using a template. Also shows how to schedule an email for a specific time. ```ruby # Simple message message = { from_email: 'sender@example.com', to: [{ email: 'user@example.com' }], subject: 'Subject', text: 'Text body', html: 'HTML body' } response = client.messages.send({ message: message }) # With template response = client.messages.send_template({ template_name: 'template-name', message: { from_email: 'sender@example.com', to: [...] } }) # Scheduled response = client.messages.send({ message: message, send_at: '2024-12-25 10:00:00' }) ``` -------------------------------- ### Get Webhook Info Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieves information about a specific webhook by its ID. ```APIDOC ## POST /webhooks/info ### Description Retrieves information about a specific webhook by its ID. ### Method POST ### Endpoint /webhooks/info ### Parameters #### Request Body - **id_hash** (object) - Required - Contains the ID of the webhook. ### Request Example ```json { "id_hash": "..." } ``` ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Get Senders Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieves a list of the user's sending domains. ```APIDOC ## GET /users/senders ### Description Retrieves a list of the user's sending domains. ### Method GET ### Endpoint /users/senders ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Initialize RejectsApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/rejects_api.md Instantiate the RejectsApi with an ApiClient. The default ApiClient is used if none is provided. ```ruby MailchimpTransactional::RejectsApi.new(api_client) ``` -------------------------------- ### Get Message Content Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieves the content of a specific message by its ID. ```APIDOC ## POST /messages/content ### Description Retrieves the content of a specific message by its ID. ### Method POST ### Endpoint /messages/content ### Parameters #### Request Body - **id_hash** (object) - Required - Contains the ID of the message. ### Request Example ```json { "id_hash": "..." } ``` ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Initialize UsersApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/users_api.md Instantiate the UsersApi class with an ApiClient instance. The default ApiClient will be used if none is provided. ```ruby MailchimpTransactional::UsersApi.new(api_client) ``` -------------------------------- ### Get Template Info Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieves information about a specific template by its name. ```APIDOC ## POST /templates/info ### Description Retrieves information about a specific template by its name. ### Method POST ### Endpoint /templates/info ### Parameters #### Request Body - **name_hash** (object) - Required - Contains the name of the template. ### Request Example ```json { "name_hash": "..." } ``` ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Get User Info Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieves information about the authenticated user's account. ```APIDOC ## GET /users/info ### Description Retrieves information about the authenticated user's account. ### Method GET ### Endpoint /users/info ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Get Message Info Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieves detailed information about a specific message by its ID. ```APIDOC ## POST /messages/info ### Description Retrieves detailed information about a specific message by its ID. ### Method POST ### Endpoint /messages/info ### Parameters #### Request Body - **id_hash** (object) - Required - Contains the ID of the message. ### Request Example ```json { "id_hash": "..." } ``` ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Use Environment Variables for API Keys Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/configuration.md Demonstrates the best practice of fetching API keys from environment variables, raising an error if the variable is not set, to avoid hardcoding sensitive credentials. ```ruby # Always use environment variables, never hardcode API keys api_key = ENV.fetch('MAILCHIMP_TRANSACTIONAL_API_KEY') do raise "MAILCHIMP_TRANSACTIONAL_API_KEY environment variable not set" end client = MailchimpTransactional::Client.new(api_key) ``` -------------------------------- ### Common Allowlist and Reject Management Patterns Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Illustrates how to manage email allowlists and rejects, including listing, adding, and deleting entries. ```ruby client.allowlists.list() client.allowlists.add(email_hash) client.allowlists.delete(email_hash) client.rejects.list() client.rejects.add(email_hash) client.rejects.delete(email_hash) ``` -------------------------------- ### Configure and Manage Webhooks Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Demonstrates how to add, list, and update webhooks for receiving event notifications. Includes configuration for URL, events, and authentication. ```ruby # Create webhook webhook = { url: 'https://example.com/webhooks/mandrill', events: ['send', 'bounce', 'click', 'open'], auth_type: 'basic', auth_user: 'user', auth_pass: 'pass' } response = client.webhooks.add(webhook) # List webhooks webhooks = client.webhooks.list() # Update webhook client.webhooks.update({ id: webhook_id, events: ['send', 'bounce', 'hard_bounce', 'click'] }) ``` -------------------------------- ### Get Sender Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/senders_api.md Retrieves detailed information about a specific sender, including their reputation, bounce, and spam complaint statistics. ```APIDOC ## GET /senders/{address} ### Description Retrieves detailed information about a specific sender, including their reputation, bounce, and spam complaint statistics. ### Method GET ### Endpoint /senders/{address} ### Parameters #### Path Parameters - **address** (string) - Required - The email address of the sender to retrieve information for. ### Response #### Success Response (200) - **address** (string) - The email address of the sender. - **reputation** (integer) - The current reputation score of the sender. - **hard_bounces** (integer) - The number of hard bounces in the last 30 days. - **spam_complaints** (integer) - The number of spam complaints in the last 30 days. #### Response Example ```json { "address": "sender@example.com", "reputation": 85, "hard_bounces": 10, "spam_complaints": 2 } ``` ``` -------------------------------- ### Get Webhook Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/webhooks_api.md Fetch detailed information about a specific webhook using its ID. This allows inspection of its full configuration. ```ruby client = MailchimpTransactional::Client.new('your_api_key') webhook = client.webhooks.info({ id: 123 }) puts "Webhook URL: #{webhook['url']}" puts "Subscribed Events: #{webhook['events'].join(', ')}" ``` -------------------------------- ### Initialize Client with API Key Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/configuration.md Create a new MailchimpTransactional client instance, providing your API key during initialization. This is the primary way to authenticate your requests. ```ruby require 'MailchimpTransactional' # Create a client with API key client = MailchimpTransactional::Client.new('your_api_key') ``` -------------------------------- ### Install Mailchimp Transactional Ruby Gem Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Add the MailchimpTransactional gem to your project's Gemfile to include the client library. ```ruby gem 'MailchimpTransactional', '~> 1.4.1' ``` -------------------------------- ### Initialize AllowlistsApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/allowlists_api.md Instantiate the AllowlistsApi with an ApiClient. The default ApiClient is used if none is provided. ```ruby MailchimpTransactional::AllowlistsApi.new(api_client) ``` -------------------------------- ### Initialize IpsApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/ips_api.md Instantiate the IpsApi class with an ApiClient instance. The default ApiClient will be used if none is provided. ```ruby MailchimpTransactional::IpsApi.new(api_client) ``` -------------------------------- ### Get MC Template Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieve details about a specific Mailchimp Transactional template using its slug or ID with the `mctemplates.mc_templates_info` method. ```ruby client.mctemplates.mc_templates_info(slug: 'my-template-slug') ``` -------------------------------- ### Format Configuration for Different Use Cases Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/configuration.md Demonstrates setting the default output format to JSON, XML, or overriding it for a single request to retrieve data in PHP serialization format. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') # Use JSON for standard API usage (recommended) client.set_default_output_format('json') response = client.users.ping() # response is a Hash # Use XML for systems that prefer XML client.set_default_output_format('xml') response = client.users.ping() # response is XML string # Override for a single request response = client.users.list({ outputFormat: 'php' }) # This request gets PHP serialized response ``` -------------------------------- ### Initialize MessagesApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/messages_api.md Instantiate the MessagesApi with an ApiClient. The default ApiClient is used if none is provided. ```ruby MailchimpTransactional::MessagesApi.new(api_client) ``` -------------------------------- ### Get Dedicated IP Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/ips_api.md Retrieves detailed information about a specific dedicated IP address, including its reputation and warmup status. ```APIDOC ## GET /ips/info ### Description Retrieves information about a single dedicated IP. ### Method GET ### Endpoint /ips/info ### Parameters #### Query Parameters - **body** (Hash) - Required - Request body containing IP address - **ip** (String) - Required - IP address to query ### Request Example ```ruby client = MailchimpTransactional::Client.new('your_api_key') ip_info = client.ips.info({ ip: '192.0.2.1' }) puts "IP: #{ip_info['ip']}" puts "Reputation: #{ip_info['reputation']}" puts "Warmup Status: #{ip_info['warmup_status']}" ``` ### Response #### Success Response (200) - **Hash** - Detailed IP information with statistics. #### Response Example ```json { "ip": "192.0.2.1", "pool": "general", "status": "active", "reputation": 85, "warmup_status": false, "creation_time": "2023-01-01T10:00:00Z" } ``` ``` -------------------------------- ### Initialize ExportsApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/exports_api.md Instantiate the ExportsApi with an ApiClient. Defaults to ApiClient.default if no client is provided. ```ruby MailchimpTransactional::ExportsApi.new(api_client) ``` -------------------------------- ### Create and Publish Template Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/templates_api.md Demonstrates how to create a new email template with specified content and then publish it for use. It includes setting the template name, sender information, subject line, and HTML content. ```APIDOC ## Create and Publish Template ### Description Creates a new email template and then publishes it. This allows you to define the structure and content of your transactional emails. ### Method POST (implied by `client.templates.add` and `client.templates.publish`) ### Endpoint `/templates` (for creation) `/templates/{template_name}/publish` (for publishing) ### Parameters #### Request Body (for creation) - **name** (string) - Required - The name of the template. - **from_email** (string) - Required - The sender's email address. - **from_name** (string) - Required - The sender's name. - **subject** (string) - Required - The subject line of the email, can include merge tags. - **code** (string) - Required - The HTML content of the template, can include merge tags. #### Request Body (for publishing) - **name** (string) - Required - The name of the template to publish. ### Request Example (creation) ```json { "name": "order-confirmation", "from_email": "orders@example.com", "from_name": "Example Store", "subject": "Order Confirmation #*|ORDER_ID|*", "code": "

Thank you for your order!

Order ID: *|ORDER_ID|*

Total: *|ORDER_TOTAL|*

" } ``` ### Response (creation) - **name** (string) - The name of the created template. ### Response Example (creation) ```json { "name": "order-confirmation" } ``` ### Response (publishing) - **published_at** (string) - The timestamp when the template was published. ### Response Example (publishing) ```json { "published_at": "2023-10-27T10:00:00.000Z" } ``` ``` -------------------------------- ### Get Message Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Fetch general information about a sent message, such as its status and delivery details, using its unique ID with the `messages.info` method. ```ruby client.messages.info(id: 'message_id') ``` -------------------------------- ### Get Message Content Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieve the full content of a sent message, including headers and body, using its unique ID with the `messages.content` method. ```ruby client.messages.content(id: 'message_id') ``` -------------------------------- ### Initialize SendersApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/senders_api.md Instantiate the SendersApi with an ApiClient. The default ApiClient is used if none is provided. ```ruby MailchimpTransactional::SendersApi.new(api_client) ``` -------------------------------- ### Get IP Pool Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Obtain details about a specific IP pool, including its associated IPs and domain, using the `ips.pool_info` method. ```ruby client.ips.pool_info(pool: 'My Pool') ``` -------------------------------- ### Get Account Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/users_api.md Retrieves detailed information about the API-connected user and their account, including API connection status, username, and account settings. ```APIDOC ## GET /users/info ### Description Returns detailed information about the API-connected user and their account. ### Method GET ### Endpoint /users/info ### Parameters #### Request Body - **body** (Hash) - Optional - Request body parameters (none required) ### Response #### Success Response (200) - **Hash** - Account information including API connection status, username, and account settings. ### Request Example ```ruby client = MailchimpTransactional::Client.new('your_api_key') response = client.users.info() puts response ``` ### Response Example ```json { "public_id": "example_public_id", "username": "example_user", "reputation": 98, "hourly_quota": 10000, "hourly_consumed": 500, "daily_quota": 100000, "daily_consumed": 5000, "backlog": 0, "is_ظام": false, "api_key_status": "valid" } ``` ``` -------------------------------- ### Retrieve All Senders Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/users_api.md Get a list of all senders associated with the account, including both verified and unverified addresses. The response is an array of sender information objects. ```ruby client = MailchimpTransactional::Client.new('your_api_key') response = client.users.senders() response.each do |sender| puts "#{sender['address']} - Status: #{sender['verified']}" end ``` -------------------------------- ### Set Default Output Format Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Shows how to globally configure the client to return responses in JSON format. ```ruby # Global JSON responses client.set_default_output_format('json') ``` -------------------------------- ### Get Account Information Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/users_api.md Retrieve detailed information about the API-connected user and their account. This method returns account settings and API connection status. ```ruby client = MailchimpTransactional::Client.new('your_api_key') response = client.users.info() puts response ``` -------------------------------- ### Initialize Client with API Key Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/configuration.md Initializes the Mailchimp Transactional client using an API key fetched from an environment variable. Ensures the API key is always provided. ```ruby api_key = ENV.fetch('MAILCHIMP_TRANSACTIONAL_API_KEY') # Create client client = MailchimpTransactional::Client.new(api_key) ``` -------------------------------- ### Get MC Template Time Series Stats Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Retrieve statistical data over time for a specific Mailchimp Transactional template using the `mctemplates.mc_templates_time_series` method. ```ruby client.mctemplates.mc_templates_time_series(slug: 'my-template-slug') ``` -------------------------------- ### Get Sender Time Series Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/senders_api.md Retrieves hourly performance statistics for a specific sender address, including sent, bounced, opened, and clicked counts. ```APIDOC ## GET /senders/{address}/time-series ### Description Retrieves hourly performance statistics for a specific sender address, including sent, bounced, opened, and clicked counts. ### Method GET ### Endpoint /senders/{address}/time-series ### Parameters #### Path Parameters - **address** (string) - Required - The email address of the sender to retrieve statistics for. ### Response #### Success Response (200) - **time** (string) - The hour in ISO 8601 format. - **sent** (integer) - The number of emails sent during that hour. - **bounced** (integer) - The number of emails bounced during that hour. - **opens** (integer) - The number of emails opened during that hour. - **clicks** (integer) - The number of emails clicked during that hour. #### Response Example ```json [ { "time": "2023-10-27T10:00:00Z", "sent": 150, "bounced": 2, "opens": 30, "clicks": 5 } ] ``` ``` -------------------------------- ### Manage Email Templates Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Shows how to add, update, publish, and render email templates using the client. ```ruby # Create template client.templates.add({ name: 'welcome', code: '...', from_email: 'noreply@example.com' }) # Update and publish client.templates.update({ name: 'welcome', code: '...' }) client.templates.publish({ name: 'welcome' }) # Render with variables rendered = client.templates.render({ template_name: 'welcome', template_content: [{ name: 'user_name', content: 'John' }] }) ``` -------------------------------- ### Configure Client for Production Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/configuration.md Sets the default output format to JSON and configures longer timeouts for read, write, and connect operations, suitable for production environments. ```ruby # Configure for production (longer timeouts, JSON responses) client.set_default_output_format('json') client.set_timeout(read: 300, write: 120, connect: 60) ``` -------------------------------- ### Get Message Content Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/messages_api.md Retrieves the full content, including headers and body, of a recently sent message. The message ID is required in the request body. ```ruby client = MailchimpTransactional::Client.new('your_api_key') content = client.messages.content({ id: '123456' }) puts "From: #{content['from_email']}" puts "Subject: #{content['subject']}" puts "HTML: #{content['html']}" ``` -------------------------------- ### Create and Publish a New Template Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/templates_api.md Demonstrates how to create a new transactional email template with specified content and then publish it for use. Requires the MailchimpTransactional gem and an API key. ```ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') # Create a new template template = { name: 'order-confirmation', from_email: 'orders@example.com', from_name: 'Example Store', subject: 'Order Confirmation #*|ORDER_ID|*', code: '

Thank you for your order!

Order ID: *|ORDER_ID|*

Total: *|ORDER_TOTAL|*

' } response = client.templates.add(template) puts "Created template: #{response['name']}" # Publish the template published = client.templates.publish({ name: 'order-confirmation' }) puts "Published at: #{published['published_at']}" ``` -------------------------------- ### Get Message Info Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/messages_api.md Retrieves detailed information about a single recently sent message using its ID. Requires the message ID in the request body. ```ruby client = MailchimpTransactional::Client.new('your_api_key') message_info = client.messages.info({ id: '123456' }) puts "Subject: #{message_info['subject']}" puts "Status: #{message_info['state']}" ``` -------------------------------- ### Get All Denylisted Emails Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/rejects_api.md Retrieves the email rejection denylist. Returns up to 1000 results by default. Use this to view all currently denylisted email addresses. ```ruby client = MailchimpTransactional::Client.new('your_api_key') # Get all denylisted emails rejects = client.rejects.list() puts "Total denylisted emails: #{rejects.length}" ``` -------------------------------- ### Instantiate WebhooksApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/webhooks_api.md Instantiate the WebhooksApi class with an ApiClient instance. This is the first step to interacting with webhook functionalities. ```ruby MailchimpTransactional::WebhooksApi.new(api_client) ``` -------------------------------- ### Get Template Time Series Statistics Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/templates_api.md Retrieves hourly statistics for a template over the last 30 days. Use this to monitor template performance over time. ```ruby client = MailchimpTransactional::Client.new('your_api_key') stats = client.templates.time_series({ name: 'welcome-email' }) stats.each do |hour_stats| puts "Time: #{hour_stats['time']}, Sent: #{hour_stats['sent']}, Clicks: #{hour_stats['clicks']}" end ``` -------------------------------- ### List All Templates Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/templates_api.md Returns a list of all templates available in the account. Optionally filter by label or limit the number of results. ```ruby client = MailchimpTransactional::Client.new('your_api_key') templates = client.templates.list() puts "Total templates: #{templates.length}" templates.each do |template| puts "#{template['name']} - Created: #{template['created_at']}" end ``` -------------------------------- ### List All Configured Webhooks Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/webhooks_api.md Use this method to retrieve a list of all webhooks currently configured for your account. This is useful for monitoring and managing your webhook subscriptions. ```Ruby require 'MailchimpTransactional' client = MailchimpTransactional::Client.new('your_api_key') webhooks = client.webhooks.list() puts "Total webhooks configured: #{webhooks.length}\n\n" webhooks.each do |webhook| puts "Webhook ID: #{webhook['id']}" puts "URL: #{webhook['url']}" puts "Events:" webhook['events'].each { |event| puts " - #{event}" } puts end ``` -------------------------------- ### Access McTemplates API Module Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/client.md Interact with the Mailchimp Templates API to manage Mailchimp Transactional templates. This example shows how to list Mailchimp templates. ```ruby client.mctemplates.mc_templates_list() ``` -------------------------------- ### Tags Module Endpoints Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/endpoints.md Manage message tags. These endpoints allow for retrieving tag statistics, deleting tags, getting tag information, and listing all tags. ```APIDOC ## tags.all_time_series ### Description Get all tags stats ### Method GET ### Endpoint /tags/all-time-series ### Parameters #### Query Parameters - **tag_name** (string) - Optional - Filter results by a specific tag name. - **start_time** (string) - Optional - The start of the time range for the stats (ISO 8601 format). - **end_time** (string) - Optional - The end of the time range for the stats (ISO 8601 format). ### Response #### Success Response (200) - **stats** (array) - An array of time series data objects for all tags. - **time** (string) - The timestamp for the data point. - **sent** (integer) - The number of emails sent. - **hard_bounces** (integer) - The number of hard bounces. - **soft_bounces** (integer) - The number of soft bounces. - **rejects** (integer) - The number of rejects. - **complaints** (integer) - The number of complaints. - **unsubscribes** (integer) - The number of unsubscribes. #### Response Example { "stats": [ { "time": "2023-01-01T10:00:00.000Z", "sent": 1000, "hard_bounces": 5, "soft_bounces": 10, "rejects": 2, "complaints": 1, "unsubscribes": 3 } ] } ``` ```APIDOC ## tags.delete ### Description Delete tag ### Method POST ### Endpoint /tags/delete ### Parameters #### Request Body - **tag** (string) - Required - The tag to delete. ### Response #### Success Response (200) - **tag** (string) - The deleted tag. - **status** (string) - The status of the operation (e.g., "deleted"). #### Response Example { "tag": "my-tag", "status": "deleted" } ``` ```APIDOC ## tags.info ### Description Get tag info ### Method GET ### Endpoint /tags/info ### Parameters #### Query Parameters - **tag** (string) - Required - The tag to get information for. ### Response #### Success Response (200) - **tag** (string) - The tag name. - **metrics** (object) - Metrics for the tag. - **sent** (integer) - Number of emails sent with this tag. - **opens** (integer) - Number of unique opens. - **unique_opens** (integer) - Number of unique opens. - **clicks** (integer) - Number of unique clicks. - **unique_clicks** (integer) - Number of unique clicks. - **hard_bounces** (integer) - Number of hard bounces. - **soft_bounces** (integer) - Number of soft bounces. - **rejects** (integer) - Number of rejects. - **complaints** (integer) - Number of complaints. - **unsubscribes** (integer) - Number of unsubscribes. #### Response Example { "tag": "my-tag", "metrics": { "sent": 1000, "opens": 200, "unique_opens": 150, "clicks": 50, "unique_clicks": 40, "hard_bounces": 5, "soft_bounces": 10, "rejects": 2, "complaints": 1, "unsubscribes": 3 } } ``` ```APIDOC ## tags.list ### Description List tags ### Method GET ### Endpoint /tags/list ### Response #### Success Response (200) - **tags** (array) - An array of tag names. #### Response Example { "tags": [ "my-tag-1", "my-tag-2" ] } ``` ```APIDOC ## tags.time_series ### Description Get tag stats ### Method GET ### Endpoint /tags/time-series ### Parameters #### Query Parameters - **tag_name** (string) - Required - The tag name to get stats for. - **start_time** (string) - Optional - The start of the time range for the stats (ISO 8601 format). - **end_time** (string) - Optional - The end of the time range for the stats (ISO 8601 format). ### Response #### Success Response (200) - **stats** (array) - An array of time series data objects for the specified tag. - **time** (string) - The timestamp for the data point. - **sent** (integer) - The number of emails sent. - **hard_bounces** (integer) - The number of hard bounces. - **soft_bounces** (integer) - The number of soft bounces. - **rejects** (integer) - The number of rejects. - **complaints** (integer) - The number of complaints. - **unsubscribes** (integer) - The number of unsubscribes. #### Response Example { "stats": [ { "time": "2023-01-01T10:00:00.000Z", "sent": 100, "hard_bounces": 0, "soft_bounces": 0, "rejects": 0, "complaints": 0, "unsubscribes": 0 } ] } ``` -------------------------------- ### Instantiate TemplatesApi Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/templates_api.md Instantiate the TemplatesApi class with an ApiClient instance. The default ApiClient will be used if none is provided. ```ruby MailchimpTransactional::TemplatesApi.new(api_client) ``` -------------------------------- ### Initialize Client with API Key Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/README.md Initializes the Mailchimp Transactional client with your API key. The key is automatically included in subsequent requests. ```ruby # Initialize with API key client = MailchimpTransactional::Client.new('your_api_key') ``` -------------------------------- ### Get Information About a Specific IP Pool Source: https://github.com/mailchimp/mailchimp-transactional-ruby/blob/master/_autodocs/api-reference/ips_api.md Fetches details for a single dedicated IP pool, including the IP addresses assigned to it. Requires the pool name. ```ruby client = MailchimpTransactional::Client.new('your_api_key') pool = client.ips.pool_info({ name: 'production-pool' }) puts "Pool: #{pool['name']}" puts "IPs: #{pool['ips'].join(', ')}" ```