debug: add logging to UUID resolver to identify correct field name from Ivanti search response
This commit is contained in:
@@ -171,18 +171,49 @@ async function resolveWorkflowBatchUuid(db, submission, apiKey, clientId, skipTl
|
|||||||
size: 1
|
size: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await ivantiPost(searchUrl, searchBody, apiKey, skipTls);
|
let result;
|
||||||
if (result.status !== 200) return null;
|
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;
|
let uuid = null;
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(result.body);
|
const data = JSON.parse(result.body);
|
||||||
const batch = (data._embedded?.workflowBatches || data.content || [])[0];
|
// Spring Data REST format
|
||||||
uuid = batch?.uuid || batch?.workflowBatchUuid || null;
|
let batches = [];
|
||||||
} catch { return null; }
|
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
|
// Cache the UUID locally for future use
|
||||||
if (uuid) {
|
if (uuid && submission.id) {
|
||||||
db.run(
|
db.run(
|
||||||
`UPDATE ivanti_fp_submissions SET ivanti_workflow_batch_uuid = ? WHERE id = ?`,
|
`UPDATE ivanti_fp_submissions SET ivanti_workflow_batch_uuid = ? WHERE id = ?`,
|
||||||
[uuid, submission.id],
|
[uuid, submission.id],
|
||||||
|
|||||||
Reference in New Issue
Block a user