PlanSolve TypeScript/JavaScript SDK
A JavaScript/TypeScript client library for the PlanSolve optimization API. Solve complex optimization problems with a simple, async API.
Installation
npm
npm install plansolve
yarn
yarn add plansolve
bun
bun add plansolve
Requirements
Node.js 18+
Modern Node.js with native fetch support
Browser Support
Modern browsers with fetch API support
API Key
Optional but recommended for production use
TypeScript
Full type definitions included
API Workflow
All PlanSolve optimization APIs follow the same workflow. Understanding this process will help you integrate the API effectively.
Construct Request
Build your optimization request with the required data
Start Solver
Submit the request to start the optimization process
Poll Status
Check the status until the solver completes
Get Results
Retrieve the optimized solution
Solver SDKs
Choose your optimization solver and get started with comprehensive examples and documentation.
Field Service
Route Optimization
Optimize field technician routes, schedule customer visits, and manage service appointments with intelligent routing algorithms.
Professional Services
Task Assignment
Optimize employee task assignments, project scheduling, and resource allocation for professional service organizations.
API Reference
PlanSolveClient
The main client class for interacting with the PlanSolve API.
Constructor
new PlanSolveClient(apiKey?: string)
Methods
fieldService
- Access to field service optimization methodsprofessionalServices
- Access to professional services optimization methodsgetStatus(jobId: string)
- Get the status of a running optimization job
FieldServiceApiClient
Handles field service optimization requests and results.
Methods
start(request: FieldServiceRequest)
- Start a new field service optimizationgetResult(jobId: string)
- Get the completed optimization result
ProfessionalServicesApiClient
Handles professional services task assignment optimization requests and results.
Methods
start(request: ProfessionalServicesRequest)
- Start a new professional services optimizationgetResult(jobId: string)
- Get the completed optimization resultgetStatus(jobId: string)
- Get the status of a running optimization jobstartAndWaitForCompletion(request, pollIntervalMs?, maxAttempts?)
- Start optimization and wait for completion with polling
Data Models
Field Service Models
Vehicle
interface Vehicle {
id: string;
homeLocation: [number, number];
shifts: Shift[];
skills: string[];
}
Visit
interface Visit {
id: string;
name: string;
location: [number, number];
timeWindows: TimeWindow[];
serviceDuration: string;
priority: 'HIGH' | 'MEDIUM' | 'LOW';
requiredSkills: string[];
}
Professional Services Models
Employee
interface Employee {
id: string;
shifts: Shift[];
skills: string[];
}
Task
interface Task {
id: string;
name: string;
deadline?: string;
duration: string;
priority: string;
requiredSkills: string[];
}
Advanced Usage
Error Handling
try { const response = await client.professionalServices.start(request); // Handle success } catch (error) { if (error.message.includes('API error: 401')) { console.error('Invalid API key'); } else if (error.message.includes('API error: 400')) { console.error('Invalid request data'); } else if (error.message.includes('API error: 429')) { console.error('Rate limit exceeded'); } else { console.error('Unexpected error:', error.message); } }
Async Optimization with Polling
async function waitForCompletion(client, jobId, maxWaitMinutes = 30) { const startTime = Date.now(); const maxWaitMs = maxWaitMinutes * 60 * 1000; while (Date.now() - startTime < maxWaitMs) { const status = await client.getStatus(jobId); if (status.status === 'COMPLETED') { return await client.professionalServices.getResult(jobId); } else if (status.status === 'FAILED') { throw new Error(`Optimization failed: ${status.error || 'Unknown error'}`); } await new Promise(resolve => setTimeout(resolve, 5000)); } throw new Error('Optimization timed out'); }
Browser Usage
The SDK works in modern browsers that support the Fetch API.
<!DOCTYPE html> <html> <head> <title>PlanSolve Optimization</title> </head> <body> <script type="module"> import { PlanSolveClient } from 'https://unpkg.com/plansolve@latest/dist/plansolve.js'; const client = new PlanSolveClient('YOUR_API_KEY'); // Use the client as shown in the examples above </script> </body> </html>
Ready to Build?
Start integrating PlanSolve optimization into your applications today.