diff --git a/backend/routes/ivantiFpWorkflow.js b/backend/routes/ivantiFpWorkflow.js index 9535be7..7429fdb 100644 --- a/backend/routes/ivantiFpWorkflow.js +++ b/backend/routes/ivantiFpWorkflow.js @@ -171,18 +171,49 @@ async function resolveWorkflowBatchUuid(db, submission, apiKey, clientId, skipTl size: 1 }; - const result = await ivantiPost(searchUrl, searchBody, apiKey, skipTls); - if (result.status !== 200) return null; + let result; + try { + result = await ivantiPost(searchUrl, searchBody, apiKey, skipTls); + } catch (e) { + console.error('[resolveUUID] Search request failed:', e.message); + return null; + } + + if (result.status !== 200) { + console.error('[resolveUUID] Search returned status:', result.status, result.body?.substring(0, 200)); + return null; + } let uuid = null; try { const data = JSON.parse(result.body); - const batch = (data._embedded?.workflowBatches || data.content || [])[0]; - uuid = batch?.uuid || batch?.workflowBatchUuid || null; - } catch { return null; } + // Spring Data REST format + let batches = []; + if (data._embedded?.workflowBatches) batches = data._embedded.workflowBatches; + else if (data._embedded?.workflowBatch) batches = data._embedded.workflowBatch; + else if (data.content) batches = data.content; + else if (data.data) batches = data.data; + else if (Array.isArray(data)) batches = data; + + const batch = batches[0]; + if (batch) { + // Try common UUID field names + uuid = batch.uuid || batch.workflowBatchUuid || batch.batchUuid || batch.groupUuid || null; + if (!uuid) { + // Log all keys so we can identify the right field + console.log('[resolveUUID] Batch keys:', Object.keys(batch).join(', ')); + console.log('[resolveUUID] Batch sample:', JSON.stringify(batch).substring(0, 500)); + } + } else { + console.log('[resolveUUID] No batches found for ID:', submission.ivanti_workflow_batch_id); + } + } catch (e) { + console.error('[resolveUUID] Failed to parse search response:', e.message); + return null; + } // Cache the UUID locally for future use - if (uuid) { + if (uuid && submission.id) { db.run( `UPDATE ivanti_fp_submissions SET ivanti_workflow_batch_uuid = ? WHERE id = ?`, [uuid, submission.id],