Skip to main content
Plain has built-in importers for common providers. If your source system is supported, use those first. They handle the mapping for you. These mutations are for when you need to build a custom import, for example from a less common provider or an internal tool.
For TypeScript, the GraphQL SDK gives you a fully typed client for these operations.
The importThread and importThreadMessages mutations let you bring across historic threads while preserving original timestamps, authors, and attachments so your team has full context in Plain. Unlike createThread, imported threads do not trigger SLAs or autoresponders and are marked with import provenance tracking. The import sends nothing to the customer. Inbound and outbound messages stay on the thread, and the Customer Inbox can show them.

Overview

Importing a thread is a two-step process:
  1. Create the thread with importThread: this sets up the thread with its metadata (title, status, priority, labels, etc.) and the original creation timestamp.
  2. Add messages with importThreadMessages: this adds the conversation history (inbound messages, outbound replies, and internal notes) to the thread.
You must create the thread before importing its messages. Each mutation is idempotent: if you call it again with the same externalId, the duplicate is skipped (the result will be NOOP). To change a message you already imported, see Update an imported message.

Permissions

To import threads you need an API key with the following permissions:
  • thread:import
  • attachment:create (if importing messages with attachments)

Import a thread

The importThread mutation creates a thread tied to an existing customer. You can identify the customer by their Plain customer ID, email address, or external ID. The statusDetail.type must match the thread status:
  • TODO allows NEW_REPLY or IN_PROGRESS
  • SNOOZED allows WAITING_FOR_CUSTOMER
  • DONE allows DONE_MANUALLY_SET or IGNORED
If you provide a tenantId, the customer must already be a member of the account or the import will fail.
Mutation
Variables
The mutation returns a result field which is one of:
  • CREATED: the thread was imported successfully.
  • NOOP: a thread with this externalId already exists, so the import was skipped.

Import thread messages

Once you have a thread, use importThreadMessages to add conversation history. You can import up to 25 messages per call. Each message has a type that determines which author field to set, and whether a customer can read it:
  • INBOUND: set author.customerId. Plain stores the message as a custom timeline entry.
  • OUTBOUND: set author.userId. Plain stores the message as a custom timeline entry.
  • NOTE: set author.userId. This is an internal note. Your team sees it, and the Customer Inbox leaves it out.
Exactly one of customerId or userId must be provided.
INBOUND and OUTBOUND messages are custom timeline entries. When the Customer Inbox is enabled, a customer who can open the thread can read them. There is no flag that hides a custom timeline entry.Import a comment that should stay with your team as NOTE.
Mutation
Variables
The mutation returns a results array with one entry per message in the same order as the input. Each result contains:
  • result: CREATED, UPDATED (if updateExisting updated the message), or NOOP (if a message with that externalId already exists).
  • threadMessage: the created TimelineEntry (for INBOUND/OUTBOUND) or Note (for NOTE). Null if the message failed.
  • error: per-message error details, null on success.
If some messages fail while others succeed, the top-level error will have the code bulk_partial_failure.

Importing messages with attachments

To import messages that have attachments, you need to upload the attachments first and then reference them by ID.
1

Upload the attachment

Use createAttachmentUploadUrl to get an upload URL, then upload the file. See the attachments guide for the full upload flow.When creating the upload URL, use the attachment type CUSTOM_TIMELINE_ENTRY for INBOUND and OUTBOUND messages, or NOTE for NOTE messages.
2

Reference the attachment in the message

Pass the attachment ID (returned by createAttachmentUploadUrl) in the attachmentIds array of the message:
Attachments that are uploaded but not referenced by any message are deleted after 24 hours. Make sure to call importThreadMessages promptly after uploading.

Update an imported message

Set updateExisting to true on a message to update the message you already imported with the same externalId. Without it, the import skips the message and returns NOOP. For example, you can use it to add an emailMessageId to an email you imported without one. emailMessageId is the original email’s Message-ID header, and email replies that reference it join the imported thread instead of opening a new one. This message adds an emailMessageId to msg_001 from the example above:
The result for the message is UPDATED. An update changes only these fields:
  • text, format, and attachmentIds: replaced with the values you send, so send the full message, including its attachments
  • emailMessageId: replaced only when you send one, so omit it to keep the stored value
The message’s error has one of these codes when the update can’t apply, and Plain leaves the stored message unchanged:
  • not_found: no message with that externalId exists on the thread
  • thread_is_locked: the thread is locked
  • cannot_update_field: the type or author differs from the stored message
NOTE messages don’t support updateExisting. Plain rejects the whole call with input_validation, so update notes with updateNote instead. An update doesn’t move replies that arrived before it. They stay on the threads they opened, and replies to them keep joining those threads.

Putting it all together

A typical migration script follows this order:
  1. Upsert customers so they exist in Plain.
  2. Call importThread for each ticket in the source system.
  3. Upload any attachments using createAttachmentUploadUrl.
  4. Call importThreadMessages with the thread ID and messages (in batches of up to 25).
  5. Check the result and error fields to confirm each import succeeded.
Since both mutations are idempotent on externalId, you can safely re-run a migration script without creating duplicates.