Document Types

List, inspect, and validate document types and their schemas

Document Types

Document types define what data DocuTray extracts from your documents. Each type has a JSON schema that describes the fields to extract. Use the Document Types API to list available types, inspect their schemas, and validate extracted data.

List Document Types

Retrieve all document types accessible to your organization, including public types and your custom types.

from docutray import Client

client = Client(api_key="YOUR_API_KEY")

# List all document types
page = client.document_types.list()

for doc_type in page.data:
    print(f"{doc_type.codeType}: {doc_type.name}")

# Auto-paginate through all results
for doc_type in client.document_types.list().auto_paging_iter():
    print(f"{doc_type.codeType}: {doc_type.name}")
import DocuTray from 'docutray';

const client = new DocuTray({ apiKey: 'YOUR_API_KEY' });

// List all document types
const page = await client.documentTypes.list();

for (const docType of page.data) {
  console.log(`${docType.codeType}: ${docType.name}`);
}

// Auto-paginate through all results
for await (const docType of client.documentTypes.list().autoPagingIter()) {
  console.log(`${docType.codeType}: ${docType.name}`);
}
curl https://app.docutray.com/api/document-types \
  -H "Authorization: Bearer YOUR_API_KEY"

# With search and pagination
curl "https://app.docutray.com/api/document-types?search=invoice&page=1&limit=20" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

# page is a Page[DocumentType]
print(f"Total: {page.pagination.total}")
print(f"Page: {page.pagination.page}")

for dt in page.data:
    print(f"  {dt.name} ({dt.codeType})")
    print(f"  Public: {dt.isPublic}, Draft: {dt.isDraft}")
// page is a Page<DocumentType>
console.log(`Total: ${page.pagination.total}`);
console.log(`Page: ${page.pagination.page}`);

for (const dt of page.data) {
  console.log(`  ${dt.name} (${dt.codeType})`);
  console.log(`  Public: ${dt.isPublic}, Draft: ${dt.isDraft}`);
}
{
  "data": [
    {
      "id": "cm5vm9hx30001m5cgh0p9v8qa",
      "name": "Invoice",
      "codeType": "invoice",
      "description": "Standard invoice document",
      "isPublic": true,
      "isDraft": false,
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    }
  ],
  "pagination": {
    "total": 50,
    "page": 1,
    "limit": 20
  }
}

Search and Pagination

# Search by name or code
page = client.document_types.list(search="invoice")

# Manual pagination
page = client.document_types.list(page=1, limit=10)

# Iterate through all pages
for page_chunk in client.document_types.list().iter_pages():
    print(f"Page {page_chunk.page}: {len(page_chunk.data)} items")
// Search by name or code
const page = await client.documentTypes.list({ search: 'invoice' });

// Manual pagination
const page2 = await client.documentTypes.list({ page: 1, limit: 10 });

// Iterate through all pages
for await (const pageChunk of client.documentTypes.list().iterPages()) {
  console.log(`Page: ${pageChunk.data.length} items`);
}
# Search by name
curl "https://app.docutray.com/api/document-types?search=invoice" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Page 2 with 10 results per page
curl "https://app.docutray.com/api/document-types?page=2&limit=10" \
  -H "Authorization: Bearer YOUR_API_KEY"

Get Document Type

Retrieve a specific document type by ID, including its full JSON schema.

doc_type = client.document_types.get("dt_abc123")

print(f"Name: {doc_type.name}")
print(f"Code: {doc_type.codeType}")
print(f"Description: {doc_type.description}")
print(f"Schema: {doc_type.schema_}")
const docType = await client.documentTypes.get('dt_abc123');

console.log(`Name: ${docType.name}`);
console.log(`Code: ${docType.codeType}`);
console.log(`Description: ${docType.description}`);
console.log('Schema:', JSON.stringify(docType.schema, null, 2));
curl https://app.docutray.com/api/document-types/dt_abc123 \
  -H "Authorization: Bearer YOUR_API_KEY"

Validate Data

Validate extracted data against a document type's schema. Useful for checking data quality after conversion or before submitting to downstream systems.

result = client.document_types.validate(
    "dt_invoice",
    {"invoice_number": "INV-001", "total": 100}
)

if result.is_valid():
    print("Data is valid!")
else:
    for error in result.errors.messages:
        print(f"Error: {error}")
    for warning in result.warnings.messages:
        print(f"Warning: {warning}")
const result = await client.documentTypes.validate('dt_invoice', {
  invoice_number: 'INV-001',
  total: 100,
});

if (result.errors.count === 0) {
  console.log('Schema is valid!');
} else {
  for (const error of result.errors.messages) {
    console.log(`Error: ${error}`);
  }
}

if (result.warnings?.count > 0) {
  for (const warning of result.warnings.messages) {
    console.log(`Warning: ${warning}`);
  }
}

Understanding Schemas

Each document type has a JSON schema that defines the fields DocuTray extracts. For example, an invoice schema might look like:

{
  "type": "object",
  "properties": {
    "invoice_number": {
      "type": "string",
      "description": "Invoice number or identifier"
    },
    "issue_date": {
      "type": "string",
      "format": "date",
      "description": "Date the invoice was issued"
    },
    "vendor_name": {
      "type": "string",
      "description": "Name of the issuing company"
    },
    "line_items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": { "type": "string" },
          "quantity": { "type": "number" },
          "unit_price": { "type": "number" },
          "amount": { "type": "number" }
        }
      }
    },
    "subtotal": { "type": "number" },
    "tax": { "type": "number" },
    "total": { "type": "number" }
  }
}

The schema determines which fields are extracted during conversion and what data types they should have.

Parameters

List Parameters

ParameterTypeRequiredDescription
searchstringNoSearch by name, code, or description
pageintegerNoPage number (default: 1)
limitintegerNoItems per page, 1-100 (default: 20)

Get Parameters

ParameterTypeRequiredDescription
idstringYesDocument type ID

Complete Code

from docutray import Client, NotFoundError, DocuTrayError

client = Client(api_key="YOUR_API_KEY")

try:
    # List available document types
    print("Available document types:")
    for doc_type in client.document_types.list().auto_paging_iter():
        status = "published" if not doc_type.isDraft else "draft"
        scope = "public" if doc_type.isPublic else "private"
        print(f"  [{status}/{scope}] {doc_type.name} ({doc_type.codeType})")

    # Get details for a specific type
    invoice_type = client.document_types.get("dt_abc123")
    print(f"\nSchema for {invoice_type.name}:")
    print(invoice_type.schema_)

except NotFoundError:
    print("Document type not found")
except DocuTrayError as e:
    print(f"Error: {e.message}")
finally:
    client.close()
import DocuTray, { NotFoundError, DocuTrayError } from 'docutray';

const client = new DocuTray({ apiKey: 'YOUR_API_KEY' });

try {
  // List available document types
  console.log('Available document types:');
  for await (const docType of client.documentTypes.list().autoPagingIter()) {
    const status = docType.isDraft ? 'draft' : 'published';
    const scope = docType.isPublic ? 'public' : 'private';
    console.log(`  [${status}/${scope}] ${docType.name} (${docType.codeType})`);
  }

  // Get details for a specific type
  const invoiceType = await client.documentTypes.get('dt_abc123');
  console.log(`\nSchema for ${invoiceType.name}:`);
  console.log(JSON.stringify(invoiceType.schema, null, 2));
} catch (error) {
  if (error instanceof NotFoundError) {
    console.error('Document type not found');
  } else if (error instanceof DocuTrayError) {
    console.error(`Error: ${error.message}`);
  }
}

SDK Reference

For detailed class and method documentation:

On this page