Workflow Management
The Nanonets Node.js SDK provides comprehensive functionality for managing workflows. This guide covers all available methods for workflow management, fully aligned with the Nanonets API.
Setup
Minimum Node.js version required: 14.0.0
Install the Nanonets Node.js SDK using npm:
npm install nanonets
Workflow Schema & Limits
- Workflow fields and table headers must be alphanumeric with underscores only, unique within the workflow, and cannot contain spaces or special characters.
- Limits:
- Max 20 workflows per account
- Max 30 fields per workflow
- Max 20 table headers per workflow
List Workflows
Retrieves a list of all workflows in your account.
const workflows = await client.workflows.list();
Get Workflow by ID
Retrieves detailed information about a specific workflow, including its configuration, fields, table headers, and settings.
const workflow = await client.workflows.get("workflow_123");
Get Available Workflow Types
Retrieves a list of all available workflow types you can use when creating a new workflow. Each type represents a different document processing model (e.g., invoice, receipt, passport).
const workflowTypes = await client.workflows.getTypes();
workflowTypes.forEach(t => {
console.log(`ID: ${t.id}, Name: ${t.name}, Description: ${t.description}`);
});
Create Workflow
Creates a new workflow with the specified type. For instant learning workflows, you must configure fields after creation.
// Create instant learning workflow (requires field configuration after creation)
const workflow = await client.workflows.create({
description: "Extract data from custom documents",
workflow_type: "" // Empty string for instant learning
});
// Create pre-trained workflow (fields are pre-configured, can be modified later)
const workflow2 = await client.workflows.create({
description: "Extract data from invoices",
workflow_type: "invoice"
});
Set Fields and Table Headers
Configures the fields and table headers to extract from documents. This replaces all existing fields and table headers.
const workflow = await client.workflows.setFields("workflow_123", {
fields: [
{ name: "invoice_number" },
{ name: "total_amount" },
{ name: "invoice_date" }
],
table_headers: [
{ name: "item_description" },
{ name: "quantity" },
{ name: "unit_price" },
{ name: "total" }
]
});
Update Field or Table Header
Modifies an existing field or table header configuration. Only the name can be updated, and it must remain unique and valid.
const workflow = await client.workflows.updateField("workflow_123", "field_123", {
name: "invoice_number"
});
Delete Field or Table Header
Removes a specific field or table header from the workflow.
await client.workflows.deleteField("workflow_123", "field_123");
Update Workflow Metadata
Modifies the workflow's description. (Name is not a supported property in the API.)
const workflow = await client.workflows.updateMetadata("workflow_123", {
description: "Updated workflow description"
});
Update Workflow Settings
Configures table capture settings for the workflow.
const workflow = await client.workflows.updateSettings("workflow_123", {
table_capture: true // Enable or disable table capture
});
Error Handling & Common Scenarios
API error codes:
- 200 OK: Request successful
- 201 Created: Resource created
- 400 Bad Request: Invalid parameters, exceeded limits, or invalid field/table header names
- 401 Unauthorized: Invalid/missing API key
- 404 Not Found: Workflow or field not found
- 409 Conflict: Resource already exists
- 500 Internal Server Error: Server-side error
Common error scenarios:
- Invalid field/table header names (must be alphanumeric/underscore, unique)
- Exceeding workflow/field/table header limits
- Missing field configuration for instant learning workflows
const { NanonetsError, AuthenticationError, ValidationError } = require('nanonets');
try {
const workflow = await client.workflows.create({...});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Authentication failed:", error.message);
} else if (error instanceof ValidationError) {
console.error("Invalid input:", error.message);
} else if (error instanceof NanonetsError) {
console.error("An error occurred:", error.message);
}
}
Best Practices
- Use clear, descriptive, and unique field/table header names (e.g., "invoice_number")
- For instant learning, always configure fields after workflow creation
- Use table capture settings as needed for your use case
- Monitor limits and handle errors gracefully
For more detailed information about specific features, see:
For more information about document processing, see the Document Processing section.