Workflow Management
The Nanonets Go SDK provides comprehensive functionality for managing workflows. This guide covers all available methods for workflow management, fully aligned with the Nanonets API.
Setup
Minimum Go version required: 1.18
Install the Nanonets Go SDK:
go get github.com/nanonets/nanonets-go-sdk
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.
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflows, err := client.Workflows.List(ctx)
if err != nil {
log.Fatal(err)
}
Get Workflow by ID
Retrieves detailed information about a specific workflow, including its configuration, fields, table headers, and settings.
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflow, err := client.Workflows.Get(ctx, "workflow_123")
if err != nil {
log.Fatal(err)
}
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).
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflowTypes, err := client.Workflows.GetTypes(ctx)
if err != nil {
log.Fatal(err)
}
for _, t := range workflowTypes {
fmt.Printf("ID: %s, Name: %s, Description: %s\n", t.ID, t.Name, t.Description)
}
Create Workflow
Creates a new workflow with the specified type. For instant learning workflows, you must configure fields after creation.
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
// Create instant learning workflow (requires field configuration after creation)
workflow, err := client.Workflows.Create(ctx, &nanonets.CreateWorkflowRequest{
Description: "Extract data from custom documents",
WorkflowType: "", // Empty string for instant learning
})
if err != nil {
log.Fatal(err)
}
// Create pre-trained workflow (fields are pre-configured, can be modified later)
workflow, err = client.Workflows.Create(ctx, &nanonets.CreateWorkflowRequest{
Description: "Extract data from invoices",
WorkflowType: "invoice",
})
if err != nil {
log.Fatal(err)
}
Set Fields and Table Headers
Configures the fields and table headers to extract from documents. This replaces all existing fields and table headers.
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflow, err := client.Workflows.SetFields(ctx, "workflow_123", &nanonets.SetFieldsRequest{
Fields: []nanonets.Field{
{Name: "invoice_number"},
{Name: "total_amount"},
{Name: "invoice_date"},
},
TableHeaders: []nanonets.TableHeader{
{Name: "item_description"},
{Name: "quantity"},
{Name: "unit_price"},
{Name: "total"},
},
})
if err != nil {
log.Fatal(err)
}
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.
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflow, err := client.Workflows.UpdateField(ctx, "workflow_123", "field_123", &nanonets.UpdateFieldRequest{
Name: "invoice_number",
})
if err != nil {
log.Fatal(err)
}
Delete Field or Table Header
Removes a specific field or table header from the workflow.
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
err := client.Workflows.DeleteField(ctx, "workflow_123", "field_123")
if err != nil {
log.Fatal(err)
}
Update Workflow Metadata
Modifies the workflow's description. (Name is not a supported property in the API.)
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflow, err := client.Workflows.UpdateMetadata(ctx, "workflow_123", &nanonets.UpdateMetadataRequest{
Description: "Updated workflow description",
})
if err != nil {
log.Fatal(err)
}
Update Workflow Settings
Configures table capture settings for the workflow.
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflow, err := client.Workflows.UpdateSettings(ctx, "workflow_123", &nanonets.UpdateSettingsRequest{
TableCapture: true, // Enable or disable table capture
})
if err != nil {
log.Fatal(err)
}
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
import (
"github.com/NanoNets/nanonets-go/nanonets"
)
client := nanonets.NewClient("your_api_key")
workflow, err := client.Workflows.Create(ctx, &nanonets.CreateWorkflowRequest{...})
if err != nil {
switch {
case errors.Is(err, nanonets.ErrAuthentication):
log.Printf("Authentication failed: %v", err)
case errors.Is(err, nanonets.ErrValidation):
log.Printf("Invalid input: %v", err)
default:
log.Printf("An error occurred: %v", err)
}
return
}
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: