# Keep an email exchange together (/workflows/message-threads)

Sam is interviewing for Alex’s job. You email Sam through your mail provider and they reply, “Tuesday works for me.” Here’s how to save both emails against Sam and the job, then read them together. You’ll need the candidate and job IDs from the [placement walkthrough](/workflows/headless-ats).

## 1. Record the email you sent [#1-record-the-email-you-sent]

Send `recordTouch` with the candidate ID, job ID and the time the email went out. Give the email its own `externalId`. Use `externalThreadId` for the conversation it belongs to. If your provider reuses IDs across mailboxes, include a stable mailbox identifier in that thread ID. Keep the returned person ID for step 3. [Record a message](/api/reference/mutations/record-touch)

```graphql
mutation RecordSentEmail($candidate: ID!, $job: ID!) {
  recordTouch(input: {
    candidateId: $candidate, jobId: $job, channel: EMAIL, direction: OUTGOING
    occurredAt: "2027-01-03T09:00:00Z", body: "Does Tuesday work for you?"
    externalSource: "agency-mail", externalId: "message-41", externalThreadId: "desk-one/34"
  }) {
    wasCreated
    touch { id person { id } }
  }
}
```

## 2. Add Sam’s reply [#2-add-sams-reply]

Make the same call with `direction: INCOMING`, Sam’s words and the reply time. Use the reply’s own message ID, for example `message-42`. Keep the same person, source and thread ID. If your mail integration delivers the reply twice, repeating its message ID for Sam returns the original touch. [Message inputs](/api/reference/inputs/record-touch-input)

## 3. Read the exchange [#3-read-the-exchange]

Use the person ID from step 1 to run this query. The outgoing email comes first even if the reply reached the ATS first. For a longer exchange, use `endCursor` as `after` to read the next page. [Read a person’s thread](/api/reference/objects/person#touch-thread) · [Download the calls](/examples/message-threads.graphql)

```graphql
query ReadSamsEmail($person: ID!, $after: String) {
  person(id: $person) {
    touchThread(filter: { externalSource: "agency-mail", externalThreadId: "desk-one/34" }, first: 20, after: $after) {
      edges { node { occurredAt direction body job { id } } }
      pageInfo { endCursor hasNextPage }
    }
  }
}
```