Module: Resend::Contacts::Imports

Defined in:
lib/resend/contacts/imports.rb

Overview

Contact Imports API wrapper

Class Method Summary collapse

Class Method Details

.create(params) ⇒ Object

Create a new contact import from a CSV file.

resend.com/docs/api-reference/contacts/create-contact-import

Parameters:

  • params (Hash)

    the parameters

Options Hash (params):

  • :file (String, IO)

    CSV file content (required). Maximum size is 50MB.

  • :column_map (Hash, String)

    optional mapping of contact fields to CSV columns. Accepts a Hash (will be JSON-encoded) or a pre-encoded JSON String.

  • :on_conflict (String)

    optional conflict strategy: ‘upsert’ or ‘skip’ (default ‘skip’).

  • :segments (Array, String)

    optional list of segment IDs to add contacts to. Accepts an Array of segment ID strings (will be JSON-encoded as [“id”:“…”]) or a pre-encoded JSON String.

  • :topics (Array, String)

    optional list of topic subscription objects. Each element must be a Hash with ‘id` (String) and `subscription` (’opt_in’ or ‘opt_out’). Accepts an Array of Hashes (will be JSON-encoded) or a pre-encoded JSON String.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
# File 'lib/resend/contacts/imports.rb', line 24

def create(params)
  raise ArgumentError, "Missing required `file` field" if params[:file].nil?

  # Normalize segments: convert array of IDs to [{id: ...}] format
  if params[:segments].is_a?(Array)
    params = params.merge(segments: params[:segments].map { |s| s.is_a?(String) ? { id: s } : s })
  end

  Resend::MultipartRequest.new("contacts/imports", params, "post").perform
end

.get(id) ⇒ Object

Retrieve a single contact import by ID.

resend.com/docs/api-reference/contacts/get-contact-import

Parameters:

  • id (String)

    the contact import ID (required)

Raises:

  • (ArgumentError)


41
42
43
44
45
# File 'lib/resend/contacts/imports.rb', line 41

def get(id)
  raise ArgumentError, "Missing required `id` field" if id.nil? || id.empty?

  Resend::Request.new("contacts/imports/#{id}", {}, "get").perform
end

.list(params = {}) ⇒ Object

Parameters:

  • params (Hash) (defaults to: {})

    optional filtering and pagination parameters

Options Hash (params):

  • :status (String)

    filter by status: ‘queued’, ‘in_progress’, ‘completed’, or ‘failed’

  • :limit (Integer)

    number of results to return

  • :after (String)

    cursor for forward pagination

  • :before (String)

    cursor for backward pagination



57
58
59
60
# File 'lib/resend/contacts/imports.rb', line 57

def list(params = {})
  path = Resend::PaginationHelper.build_paginated_path("contacts/imports", params)
  Resend::Request.new(path, {}, "get").perform
end