The solution involves three key aspects of proper genealogy API usage:
API Payload Structure:
Never mix parent and child creation in a single batch. The genealogy API payload must separate hierarchical levels. Structure your imports as:
Phase 1 - Parent/Assembly creation:
POST /api/genealogy/items/batch
{"items": [{"serial": "ASM-100", "type": "assembly", "material": "MAT-500"}]}
Phase 2 - Child/Component creation with parent links:
POST /api/genealogy/items/batch
{"items": [{"serial": "SN001", "type": "component", "parentSerial": "ASM-100", "position": "1"}]}
Parent-Child Relationship Requirements:
The genealogy module validates parent existence before establishing links. This validation occurs at the database constraint level, so parent records must be fully committed and visible to subsequent transactions. In SOC 4.1, batch operations execute in a single transaction context, meaning child items processed in the same batch cannot reference parents created earlier in that same batch - they see the pre-transaction database state.
Traceability Compliance Best Practices:
For regulatory compliance, implement verification after each import phase:
// Pseudocode - Two-phase genealogy import:
1. Extract all parent/assembly items from source data
2. POST parents batch to genealogy API, await 201 response
3. Query genealogy API to verify all parents exist (GET /api/genealogy/items?serials=...)
4. Extract child/component items from source data
5. Enrich child payload with validated parentSerial references
6. POST children batch to genealogy API
7. Verify parent-child links via genealogy tree query
// Log any missing links for compliance audit trail
Additionally, enable genealogy API response logging to capture any silent validation failures. The 200 OK response you’re seeing likely contains warning messages in the response body about failed link creation - check the “warnings” array in the JSON response.
For high-volume imports (500+ items), consider implementing micro-batches of 50-100 items per API call within each phase. This improves transaction performance and makes error isolation easier when links fail.
If you’re in a clustered deployment, add a 2-3 second delay between Phase 1 and Phase 2 to allow database replication lag. Some installations have asynchronous replication between nodes, and immediate queries after parent creation may not see newly committed records on replica nodes.