Appearance
API Reference Overview
Technical documentation for developers
Introduction
ErgoPlanner provides APIs for integration with external systems, automation, and custom development. This section documents available interfaces.
API Types
REST API
For server-side integration:
- Project management
- Simulation execution
- Results retrieval
- User authentication
JavaScript SDK
For browser-based extensions:
- Canvas manipulation
- Custom components
- Event handling
- UI extensions
Authentication
API Keys
Generate API keys in Account Settings > API Keys:
javascript
// Include in request headers
Authorization: Bearer YOUR_API_KEYOAuth 2.0
For third-party applications:
- Authorization code flow
- Token refresh
- Scope-based permissions
REST API Endpoints
Projects
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/projects | List projects |
| POST | /api/projects | Create project |
| GET | /api/projects/:id | Get project |
| PUT | /api/projects/:id | Update project |
| DELETE | /api/projects/:id | Delete project |
Simulations
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/projects/:id/simulate | Run simulation |
| GET | /api/projects/:id/results | Get results |
| GET | /api/projects/:id/streams | Get stream data |
Units
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/units | List unit types |
| GET | /api/units/:type | Get unit schema |
JavaScript SDK
Installation
html
<!-- Via CDN -->
<script src="https://cdn.ergoplanner.com/sdk.js"></script>bash
# Via npm
npm install @ergoplanner/sdkBasic Usage
javascript
import { ErgoPlanner } from '@ergoplanner/sdk';
// Initialize
const ep = new ErgoPlanner({
apiKey: 'YOUR_API_KEY'
});
// Load project
const project = await ep.projects.get('project-id');
// Run simulation
const results = await project.simulate({
type: 'steady-state'
});
// Access results
console.log(results.effluent.TSS);Event Handling
javascript
// Listen for simulation complete
project.on('simulation:complete', (results) => {
console.log('Simulation finished:', results);
});
// Listen for unit selection
project.on('unit:selected', (unit) => {
console.log('Selected:', unit.id);
});Data Formats
Project JSON
json
{
"id": "project-123",
"name": "Sample Plant",
"units": [
{
"id": "unit-1",
"type": "CSTR",
"properties": {
"volume": 5000,
"MLSS": 3500
}
}
],
"connections": [
{
"from": "unit-1",
"to": "unit-2",
"type": "liquid"
}
]
}Results JSON
json
{
"status": "converged",
"iterations": 45,
"streams": {
"effluent": {
"flow": 10000,
"TSS": 12,
"COD": 35,
"NH4": 1.5
}
},
"massBalance": {
"COD": {
"in": 5000,
"out": 350,
"removed": 4650
}
}
}Rate Limits
| Plan | Requests/hour |
|---|---|
| Free | 100 |
| Professional | 1,000 |
| Enterprise | 10,000 |
Error Handling
HTTP Status Codes
| Code | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not found |
| 429 | Rate limited |
| 500 | Server error |
Error Response
json
{
"error": {
"code": "INVALID_PARAMETER",
"message": "Volume must be positive",
"field": "units[0].properties.volume"
}
}Webhooks
Configure webhooks for event notifications:
Supported Events
| Event | Trigger |
|---|---|
| simulation.complete | Simulation finishes |
| project.updated | Project saved |
| export.ready | Export file ready |
Webhook Payload
json
{
"event": "simulation.complete",
"timestamp": "2024-01-15T10:30:00Z",
"project_id": "project-123",
"data": {
"status": "converged",
"duration_ms": 1250
}
}SDK Examples
Custom Unit Type
javascript
// Register custom unit
ep.units.register({
type: 'MyCustomUnit',
schema: {
properties: {
efficiency: { type: 'number', min: 0, max: 1 }
}
},
calculate: (inputs, params) => {
return {
COD: inputs.COD * (1 - params.efficiency)
};
}
});Batch Simulations
javascript
// Run multiple scenarios
const scenarios = [
{ influent: { COD: 400 } },
{ influent: { COD: 500 } },
{ influent: { COD: 600 } }
];
const results = await Promise.all(
scenarios.map(s => project.simulate(s))
);
// Compare results
results.forEach((r, i) => {
console.log(`Scenario ${i}: Effluent COD = ${r.effluent.COD}`);
});Support
Resources
Contact
- Technical support: api-support@ergoplanner.com
- Documentation issues: docs@ergoplanner.com