diff --git a/app/api/leantime/status-labels/route.ts b/app/api/leantime/status-labels/route.ts index 5298a43a..e715ceb9 100644 --- a/app/api/leantime/status-labels/route.ts +++ b/app/api/leantime/status-labels/route.ts @@ -13,20 +13,45 @@ export async function GET() { console.log('Fetching status labels for user:', session.user.id); console.log('Using LEANTIME_TOKEN:', process.env.LEANTIME_TOKEN ? 'Present' : 'Missing'); + // First, get the Leantime user ID for the current user + const userResponse = await fetch('https://agilite.slm-lab.net/api/jsonrpc', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': process.env.LEANTIME_TOKEN || '', + }, + body: JSON.stringify({ + method: 'leantime.rpc.Users.Users.getUserByEmail', + jsonrpc: '2.0', + id: 1, + params: { + email: session.user.email + } + }) + }); + + const userData = await userResponse.json(); + console.log('User lookup response:', userData); + + if (!userData.result || !userData.result.id) { + throw new Error('Could not find Leantime user ID'); + } + + const leantimeUserId = userData.result.id; + + // Now fetch the status labels const response = await fetch('https://agilite.slm-lab.net/api/jsonrpc', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-API-Key': process.env.LEANTIME_TOKEN || '', - 'Accept': 'application/json', - 'Authorization': `Bearer ${session.accessToken}`, }, body: JSON.stringify({ method: 'leantime.rpc.Tickets.Tickets.getAllStatusLabelsByUserId', jsonrpc: '2.0', id: 1, params: { - userId: session.user.id, + userId: leantimeUserId } }) });