Here’s a comprehensive solution addressing all three aspects of your issue:
Task ID Validation:
The API requires internal numeric IDs, not display codes. Always use the lookup endpoint to resolve IDs:
GET /api/v1/project/tasks?filter=code eq 'TSK-2024-1847'
Response: {"id": 184732, "code": "TSK-2024-1847", "status": "active"}
Use the numeric “id” field (184732) in your cost allocation payload, not the “code” field.
Batch Import Error Handling:
Implement a two-phase approach. First, validate all task IDs in a pre-flight check:
// Pseudocode - Validation phase:
1. Extract all unique task_ids from your batch
2. Query lookup endpoint for each ID to get internal numeric ID
3. Check response status: active, approved, accounting_period_open
4. Build validated_tasks map: {display_code -> internal_id}
5. Flag invalid tasks for manual review
Then construct your batch with validated IDs. For the actual submission, use chunked batches of 50-100 records with individual error tracking:
POST /api/v1/project/cost-allocation/batch
{
"allocations": [
{"task_id": 184732, "amount": 15000.00, "allocation_date": "2025-03-10"},
{"task_id": 184856, "amount": 8500.00, "allocation_date": "2025-03-10"}
],
"continue_on_error": true
}
Set “continue_on_error”: true so the API processes valid records even if some fail. The response includes a detailed breakdown:
{
"processed": 2,
"successful": 1,
"failed": 1,
"errors": [{"task_id": 184856, "reason": "accounting_period_closed"}]
}
API Lookup Endpoint Usage:
Cache the task ID mappings to reduce API calls. Query the lookup endpoint once daily or when you encounter an error, then store the mappings in your integration layer. This reduces latency and API quota consumption. Also, the lookup endpoint supports bulk queries:
GET /api/v1/project/tasks?filter=code in ('TSK-2024-1847','TSK-2024-1848')
Monitor three key validation points: task status (must be “active” or “approved”), project status (must not be “closed” or “archived”), and accounting period (must be “open” for the allocation_date). These are the primary reasons for “invalid task_id” errors even when the ID format is correct.
Implement retry logic for failed records after correcting the underlying issues (reopening periods, activating tasks, etc.). Store failed records in a staging table with the specific error reason for audit purposes.