Skip to main content
POST
/
contacts
/
imports
import { readFile } from 'node:fs/promises';
import { Resend } from 'resend';

const resend = new Resend('re_xxxxxxxxx');

const file = new Blob([await readFile('contacts.csv')], {
  type: 'text/csv',
});

const { data, error } = await resend.contacts.imports.create({
  file,
  columnMap: {
    email: 'Email',
    firstName: 'First Name',
    lastName: 'Last Name',
    properties: {
      plan: {
        column: 'Plan',
        type: 'string',
      },
    },
  },
  onConflict: 'upsert',
  segments: [{ id: '78e7a5c6-9a91-4c63-9d1f-3b9c0b5b9ab6' }],
  topics: [
    {
      id: '059ac693-2fc8-4c13-8b27-01350d638a17',
      subscription: 'opt_in',
    },
  ],
});
{
  "object": "contact_import",
  "id": "479e3145-dd38-476b-932c-529ceb705947"
}

Body Parameters

This endpoint accepts multipart/form-data. Object and array fields (column_map, segments, topics) must be sent as JSON-encoded strings.
file
file
required
The CSV file to import. The file must be sent as a form field named file. Maximum file size is 100MB.
column_map
object
Maps CSV columns to contact fields.
on_conflict
'upsert' | 'skip'
How to handle contacts that already exist. Defaults to upsert.
segments
array
Array of objects. Each object must contain the ID of the segment that you’d like to add the imported contacts to.
topics
array
Array of topic subscriptions for imported contacts.
import { readFile } from 'node:fs/promises';
import { Resend } from 'resend';

const resend = new Resend('re_xxxxxxxxx');

const file = new Blob([await readFile('contacts.csv')], {
  type: 'text/csv',
});

const { data, error } = await resend.contacts.imports.create({
  file,
  columnMap: {
    email: 'Email',
    firstName: 'First Name',
    lastName: 'Last Name',
    properties: {
      plan: {
        column: 'Plan',
        type: 'string',
      },
    },
  },
  onConflict: 'upsert',
  segments: [{ id: '78e7a5c6-9a91-4c63-9d1f-3b9c0b5b9ab6' }],
  topics: [
    {
      id: '059ac693-2fc8-4c13-8b27-01350d638a17',
      subscription: 'opt_in',
    },
  ],
});
{
  "object": "contact_import",
  "id": "479e3145-dd38-476b-932c-529ceb705947"
}