Skip to content

Schemas

This page documents the data models returned by the DocMap API. All responses use JSON.

ExtractionRecord

An extraction record represents a single document extraction -- the result of processing a PDF against a template.

typescript
interface ExtractionRecord {
  id: string              // Unique extraction ID
  userId: string          // Owner user ID
  templateId: string      // Template used for extraction
  templateName: string    // Human-readable template name
  fileName: string        // Original uploaded file name
  status: 'processing' | 'completed' | 'failed'
  extractedData: Record<string, unknown> | null  // Structured data or null if failed
  error: string | null    // Error message if failed, null if successful
  variables: Variable[]   // Template variable definitions used
  source: 'dashboard' | 'api'  // How the extraction was initiated
  runId: string | null    // Batch run ID, null if not part of a batch
  processingTimeMs: number | null  // Processing duration in milliseconds
  createdAt: string       // ISO 8601 timestamp
}

Field Descriptions

FieldTypeDescription
idstringUnique identifier for the extraction record.
userIdstringThe ID of the user who owns this extraction.
templateIdstringThe ID of the template that was used to define the extraction schema.
templateNamestringThe display name of the template at the time of extraction.
fileNamestringThe original name of the uploaded file (e.g., "invoice-march.pdf").
statusstring"processing" while the extraction is running (async mode), "completed" if extraction succeeded, or "failed" if it did not.
extractedDataobject | nullThe structured data extracted from the document, matching the template's variable definitions. null if the extraction failed.
errorstring | nullA description of what went wrong. null if the extraction succeeded.
variablesVariable[]The template variable definitions that were used for this extraction. See Variable.
sourcestring"dashboard" if the extraction was run from the web UI, "api" if it was run via the API.
runIdstring | nullIf the extraction was part of a batch run, this is the shared run ID. null for individual extractions.
processingTimeMsnumber | nullHow long the extraction took in milliseconds. null if not recorded.
createdAtstringISO 8601 timestamp of when the extraction was created.

Example

json
{
  "id": "ext_kp92mf7x",
  "userId": "u_abc123",
  "templateId": "tpl_inv001",
  "templateName": "Standard Invoice",
  "fileName": "acme-invoice-2024-003.pdf",
  "status": "completed",
  "extractedData": {
    "vendor_name": "Acme Corp",
    "invoice_number": "INV-2024-003",
    "invoice_date": "2024-11-15",
    "due_date": "2024-12-15",
    "total_amount": 4750.00,
    "currency": "USD",
    "line_items": [
      {
        "description": "Cloud Hosting - Pro Plan",
        "quantity": 1,
        "unit_price": 2500.00
      },
      {
        "description": "SSL Certificate (Wildcard)",
        "quantity": 3,
        "unit_price": 750.00
      }
    ]
  },
  "error": null,
  "variables": [
    { "key": "vendor_name", "type": "string", "context": "Name of the vendor or supplier", "required": true },
    { "key": "invoice_number", "type": "string", "context": "Invoice or reference number" },
    { "key": "invoice_date", "type": "date", "context": "Date the invoice was issued" },
    { "key": "due_date", "type": "date", "context": "Payment due date" },
    { "key": "total_amount", "type": "number", "context": "Total amount due" },
    { "key": "currency", "type": "string", "context": "Currency code (e.g. USD, EUR)" },
    {
      "key": "line_items",
      "type": "array",
      "context": "Individual line items on the invoice",
      "arrayType": "object",
      "fields": [
        { "key": "description", "type": "string", "context": "Item description" },
        { "key": "quantity", "type": "number", "context": "Quantity ordered" },
        { "key": "unit_price", "type": "number", "context": "Price per unit" }
      ]
    }
  ],
  "source": "api",
  "runId": null,
  "processingTimeMs": 3842,
  "createdAt": "2024-11-20T14:30:00.000Z"
}

ApiKeyPublic

The public projection of an API key. The actual key value and its hash are never returned after creation.

typescript
interface ApiKeyPublic {
  id: string              // Key ID
  userId: string          // Owner user ID
  name: string            // Label for the key
  prefix: string          // First 16 characters of the key (e.g., "dm_live_a1b2c3d4")
  expiresAt: string | null  // ISO 8601 expiration, null if never expires
  lastUsedAt: string | null // ISO 8601 last usage, null if never used
  createdAt: string       // ISO 8601 timestamp
  revoked: boolean        // Whether the key has been revoked
}

Field Descriptions

FieldTypeDescription
idstringUnique identifier for the API key.
userIdstringThe ID of the user who owns this key.
namestringA human-readable label for the key (e.g., "Production Server").
prefixstringThe first 16 characters of the key, useful for identifying which key is in use without exposing the full value.
expiresAtstring | nullISO 8601 timestamp of when the key expires. null if the key was created with no expiration.
lastUsedAtstring | nullISO 8601 timestamp of the last time the key was used to authenticate a request. null if never used.
createdAtstringISO 8601 timestamp of when the key was created.
revokedbooleanWhether the key has been revoked. In list responses, revoked keys are filtered out, so this is typically false.

Example

json
{
  "id": "key_m3x9kq72",
  "userId": "u_abc123",
  "name": "Production Server",
  "prefix": "dm_live_a1b2c3d4",
  "expiresAt": "2025-03-15T00:00:00.000Z",
  "lastUsedAt": "2025-01-10T09:22:14.000Z",
  "createdAt": "2024-12-15T10:00:00.000Z",
  "revoked": false
}

WebhookPublic

The public projection of a webhook. The signing secret is never returned after creation.

typescript
interface WebhookPublic {
  id: string              // Webhook ID
  userId: string          // Owner user ID
  url: string             // Registered endpoint URL
  events: WebhookEvent[]  // Subscribed events
  active: boolean         // Whether the webhook is active
  createdAt: string       // ISO 8601 timestamp
}

type WebhookEvent = 'extraction.completed' | 'extraction.failed'

Field Descriptions

FieldTypeDescription
idstringUnique identifier for the webhook.
userIdstringThe ID of the user who owns this webhook.
urlstringThe HTTPS endpoint that receives webhook POST requests.
eventsstring[]The events this webhook is subscribed to. Values: "extraction.completed", "extraction.failed".
activebooleanWhether the webhook is active. In list responses, only active webhooks are returned, so this is always true.
createdAtstringISO 8601 timestamp of when the webhook was created.

Example

json
{
  "id": "webhook-abc123def456",
  "userId": "uid_a1b2c3d4e5f6",
  "url": "https://your-app.com/webhooks/docmap",
  "events": ["extraction.completed", "extraction.failed"],
  "active": true,
  "createdAt": "2025-01-15T10:00:00.000Z"
}

Variable

A variable defines a single field in an extraction template. Variables tell the AI what data to look for and what type to return it as.

typescript
interface Variable {
  key: string              // Field name in extracted data
  type: 'string' | 'number' | 'date' | 'boolean' | 'object' | 'array'
  context: string          // Description/hint for the AI extractor
  required?: boolean       // Whether the field is required
  fields?: Variable[]      // Nested fields (for type: 'object')
  arrayType?: 'string' | 'number' | 'object'  // Item type (for type: 'array')
}

Field Descriptions

FieldTypeDescription
keystringThe field name that will appear as a key in the extracted data. Must be at least 1 character.
typestringThe expected data type. One of: string, number, date, boolean, object, array.
contextstringA natural-language description that helps the AI understand what to extract for this field. More specific context produces better results.
requiredboolean(Optional) If true, the AI will always attempt to return a value for this field.
fieldsVariable[](Optional) For type: "object", defines the nested fields within the object. This is recursive -- nested objects can contain their own fields.
arrayTypestring(Optional) For type: "array", specifies the type of items in the array. One of: string, number, object. When arrayType is "object", use fields to define the shape of each item.

Recursive Structure

Variables support arbitrary nesting through the fields property. An object variable contains child variables, and an array variable with arrayType: "object" also uses fields to describe each array item.

This allows you to model complex document structures like invoices with line items, contracts with multiple parties, or any hierarchical data.

Example: Invoice Template with Nested Variables

json
[
  {
    "key": "vendor_name",
    "type": "string",
    "context": "Name of the vendor or supplier company",
    "required": true
  },
  {
    "key": "invoice_number",
    "type": "string",
    "context": "Invoice or reference number"
  },
  {
    "key": "invoice_date",
    "type": "date",
    "context": "Date the invoice was issued (YYYY-MM-DD)"
  },
  {
    "key": "total_amount",
    "type": "number",
    "context": "Total amount due including tax"
  },
  {
    "key": "billing_address",
    "type": "object",
    "context": "The billing address on the invoice",
    "fields": [
      { "key": "street", "type": "string", "context": "Street address" },
      { "key": "city", "type": "string", "context": "City name" },
      { "key": "state", "type": "string", "context": "State or province" },
      { "key": "zip", "type": "string", "context": "Postal or ZIP code" },
      { "key": "country", "type": "string", "context": "Country name or code" }
    ]
  },
  {
    "key": "line_items",
    "type": "array",
    "context": "Individual line items listed on the invoice",
    "arrayType": "object",
    "fields": [
      { "key": "description", "type": "string", "context": "Item description" },
      { "key": "quantity", "type": "number", "context": "Quantity ordered" },
      { "key": "unit_price", "type": "number", "context": "Price per unit" },
      { "key": "total", "type": "number", "context": "Line total (quantity x unit_price)" }
    ]
  },
  {
    "key": "tags",
    "type": "array",
    "context": "Keywords or categories that describe this invoice",
    "arrayType": "string"
  }
]

In this example:

  • billing_address is an object with five nested string fields.
  • line_items is an array of objects, each with description, quantity, unit_price, and total.
  • tags is a simple array of strings with no nested fields.

UsageResponse

Returned by the GET /v1/usage endpoint. Shows the authenticated user's current plan and extraction usage for the billing period.

typescript
interface UsageResponse {
  plan: 'free' | 'starter' | 'core' | 'pro'
  usage: number            // Extractions used this period
  limit: number            // Maximum for current plan
  periodKey: string        // Current period (e.g., "2025-01")
}

Field Descriptions

FieldTypeDescription
planstringThe user's current plan. One of: free, starter, core, pro.
usagenumberThe number of extractions consumed in the current billing period.
limitnumberThe maximum number of extractions allowed for the user's plan.
periodKeystringThe current billing period in YYYY-MM format (e.g., "2025-01").

Example

json
{
  "data": {
    "plan": "starter",
    "usage": 142,
    "limit": 500,
    "periodKey": "2025-01"
  }
}

TIP

The usage endpoint returns data wrapped in a data object, as shown above.

ErrorResponse

All API errors follow a consistent structure with a machine-readable code and a human-readable message.

typescript
interface ErrorResponse {
  error: {
    code: string           // Machine-readable error code
    message: string        // Human-readable description
  }
}

Example

json
{
  "error": {
    "code": "NOT_FOUND",
    "message": "Extraction not found"
  }
}

See the Error Codes reference for the full list of error codes, their HTTP status codes, and resolution steps.

DocMap API Documentation