diff --git a/backend/routes/cardApi.js b/backend/routes/cardApi.js index ac5d2ab..eed018d 100644 --- a/backend/routes/cardApi.js +++ b/backend/routes/cardApi.js @@ -595,14 +595,28 @@ function createCardApiRouter() { const hostId = req.query.hostId; // Fast path: if Ivanti hostId is provided, try asset-search first + // The asset-search returns the full record including owner data, so we can + // return directly without a separate getOwner() call. let assetId = null; if (hostId && /^\d+$/.test(hostId)) { try { const searchResult = await searchByIvantiHostId(hostId); if (searchResult.ok) { const searchData = JSON.parse(searchResult.body); - // Extract asset_id from the search response (_id field or asset_id) - assetId = searchData._id || searchData.asset_id || searchData.id || null; + const assets = searchData.assets || []; + if (assets.length > 0) { + const asset = assets[0]; + const owner = asset.owner || {}; + return res.json({ + asset_id: asset._id || null, + ip: ip.trim(), + confirmed: owner.confirmed || null, + unconfirmed: owner.unconfirmed || null, + declined: owner.declined || [], + candidate: owner.candidate || [], + update_token: owner.update_token || null, + }); + } } } catch (_) { // Fall through to suffix resolution