Flows API
The Flows API allows you to execute pre-built workflows and automations (Apps).
execute()
Execute a flow/app with structured inputs.
Signature:
typescript
client.flows.execute(options: ExecuteFlowOptions): Promise<ExecuteFlowResponse>Parameters:
options.flowId- The flow/app ID (required)options.inputs- Input data for the flow (required)options.version- Flow version to execute (optional, default:'latest')
Returns:
typescript
{
success: boolean;
outputs: Record<string, any>;
error?: string;
}Example:
typescript
// Execute an invoice analysis flow
const result = await client.flows.execute({
flowId: 'invoice-analyzer',
inputs: {
document: 'base64-encoded-pdf-content',
analysisType: 'detailed',
extractTables: true
}
});
if (result.success) {
console.log('Invoice data:', result.outputs.invoiceData);
console.log('Analysis:', result.outputs.analysis);
} else {
console.error('Flow error:', result.error);
}Common Use Cases
Document Processing
typescript
const result = await client.flows.execute({
flowId: 'document-processor',
inputs: {
document: base64Content,
outputFormat: 'json'
}
});Data Extraction
typescript
const result = await client.flows.execute({
flowId: 'data-extractor',
inputs: {
text: documentText,
schema: {
type: 'object',
properties: {
name: { type: 'string' },
date: { type: 'string' },
amount: { type: 'number' }
}
}
}
});Content Analysis
typescript
const result = await client.flows.execute({
flowId: 'content-analyzer',
inputs: {
content: articleText,
analysisType: 'sentiment',
language: 'en'
}
});Error Handling
typescript
try {
const result = await client.flows.execute({
flowId: 'my-flow',
inputs: { data: 'value' }
});
if (!result.success) {
console.error('Flow execution failed:', result.error);
return;
}
console.log('Results:', result.outputs);
} catch (error) {
console.error('API error:', error.message);
}Types
ExecuteFlowOptions
typescript
interface ExecuteFlowOptions {
flowId: string;
inputs: Record<string, any>;
version?: string;
}ExecuteFlowResponse
typescript
interface ExecuteFlowResponse {
success: boolean;
outputs: Record<string, any>;
error?: string;
}Flow Discovery
To find available flows:
- Log in to your Cognipeer workspace
- Navigate to Gallery → Apps
- Browse or install flows
- Get the flow ID from the app details
Creating Custom Flows
Flows can be created in the Cognipeer platform:
- Go to Apps → Create App
- Define your workflow steps
- Configure inputs and outputs
- Test and publish
- Use the flow ID to execute via SDK
Version Management
typescript
// Use latest version (default)
await client.flows.execute({
flowId: 'my-flow',
inputs: { ... }
});
// Use specific version
await client.flows.execute({
flowId: 'my-flow',
inputs: { ... },
version: 'v1.2.0'
});Best Practices
- Validate Inputs: Ensure required inputs are provided
- Handle Errors: Check
successfield before using outputs - Version Pinning: Use specific versions in production
- Test Flows: Test flows thoroughly before production use
- Monitor Execution: Log flow executions for debugging