GET
/
api
/
v2
/
threads
/
stats
import { Inbound } from '@inboundemail/sdk'

const inbound = new Inbound('YOUR_API_KEY')

const { data: stats, error } = await inbound.thread.getStats()

if (error) {
  console.error('Error:', error)
} else {
  console.log(`Total threads: ${stats.totalThreads}`)
  console.log(`Average messages per thread: ${stats.averageMessagesPerThread}`)
  console.log(`Unread threads: ${stats.unreadStats.unreadThreads}`)
}
{
  "totalThreads": 45,
  "totalMessages": 178,
  "averageMessagesPerThread": 3.96,
  "mostActiveThread": {
    "threadId": "thread_abc123",
    "messageCount": 12,
    "subject": "Ongoing Support Issue",
    "lastMessageAt": "2024-01-15T14:30:00Z"
  },
  "recentActivity": {
    "threadsToday": 5,
    "messagesToday": 12,
    "threadsThisWeek": 18,
    "messagesThisWeek": 67
  },
  "distribution": {
    "singleMessageThreads": 28,
    "shortThreads": 12,
    "mediumThreads": 4,
    "longThreads": 1
  },
  "unreadStats": {
    "unreadThreads": 8,
    "unreadMessages": 15
  }
}

Overview

This endpoint provides detailed statistics about email threading for your account, including thread distribution, activity metrics, and unread counts. Useful for building analytics dashboards and understanding email patterns.

Authentication

Authorization
string
required
Bearer token for API authentication. Format: Bearer YOUR_API_KEY

Response

totalThreads
integer
required
Total number of email threads in the account.
totalMessages
integer
required
Total number of messages (inbound + outbound) across all threads.
averageMessagesPerThread
number
required
Average number of messages per thread (rounded to 2 decimal places).
mostActiveThread
object | null
Information about the thread with the most messages.
recentActivity
object
required
Statistics about recent threading activity.
distribution
object
required
Distribution of threads by message count.
unreadStats
object
required
Statistics about unread messages and threads.

Examples

Request

import { Inbound } from '@inboundemail/sdk'

const inbound = new Inbound('YOUR_API_KEY')

const { data: stats, error } = await inbound.thread.getStats()

if (error) {
  console.error('Error:', error)
} else {
  console.log(`Total threads: ${stats.totalThreads}`)
  console.log(`Average messages per thread: ${stats.averageMessagesPerThread}`)
  console.log(`Unread threads: ${stats.unreadStats.unreadThreads}`)
}

Response

{
  "totalThreads": 45,
  "totalMessages": 178,
  "averageMessagesPerThread": 3.96,
  "mostActiveThread": {
    "threadId": "thread_abc123",
    "messageCount": 12,
    "subject": "Ongoing Support Issue",
    "lastMessageAt": "2024-01-15T14:30:00Z"
  },
  "recentActivity": {
    "threadsToday": 5,
    "messagesToday": 12,
    "threadsThisWeek": 18,
    "messagesThisWeek": 67
  },
  "distribution": {
    "singleMessageThreads": 28,
    "shortThreads": 12,
    "mediumThreads": 4,
    "longThreads": 1
  },
  "unreadStats": {
    "unreadThreads": 8,
    "unreadMessages": 15
  }
}

Error Responses

{
  "error": "Unauthorized"
}