missions api2

This commit is contained in:
alma 2025-05-06 16:03:33 +02:00
parent df1cc29b57
commit 9946dd8f48

View File

@ -103,19 +103,22 @@ export class LeantimeService {
// Fall back to addProject if createProject fails
console.log('createProject failed, trying addProject...');
// Based on the error message, Leantime expects a nested 'values' parameter
const payload = {
method: 'leantime.rpc.Projects.addProject',
method: 'leantime.rpc.Projects.Projects.addProject',
jsonrpc: '2.0',
id: 1,
params: {
name: mission.name,
clientId: clientId,
details: mission.intention || '',
type: 'project',
start: formattedStartDate,
end: formattedEndDate,
status: 'open',
psettings: 'restricted'
values: {
name: mission.name,
clientId: clientId,
details: mission.intention || '',
type: 'project',
start: formattedStartDate,
end: formattedEndDate,
status: 'open',
psettings: 'restricted'
}
}
};
@ -258,11 +261,11 @@ export class LeantimeService {
try {
console.log(`Assigning user ${userId} to project ${projectId} with role ${role}`);
// Try with Projects.addUser first
// Try with Projects.Projects.addUser first
const response = await axios.post(
this.getApiEndpoint(),
{
method: 'leantime.rpc.Projects.addUser',
method: 'leantime.rpc.Projects.Projects.addUser',
jsonrpc: '2.0',
id: 1,
params: {
@ -308,7 +311,35 @@ export class LeantimeService {
);
if (!altResponse.data || !altResponse.data.result) {
throw new Error(`Failed to assign user to project with both methods: ${JSON.stringify(altResponse.data)}`);
// Try one more time with the Projects.assignUserToProject format
console.log('Second method failed, trying Projects.assignUserToProject...');
const thirdResponse = await axios.post(
this.getApiEndpoint(),
{
method: 'leantime.rpc.Projects.assignUserToProject',
jsonrpc: '2.0',
id: 1,
params: {
projectId: projectId,
userId: userId,
role: role
}
},
{
headers: {
'Content-Type': 'application/json',
'X-API-Key': this.apiToken
}
}
);
if (!thirdResponse.data || !thirdResponse.data.result) {
throw new Error(`Failed to assign user to project with all methods: ${JSON.stringify(thirdResponse.data)}`);
}
console.log(`Assigned user ${userId} to project ${projectId} with role ${role} using third method`);
return;
}
console.log(`Assigned user ${userId} to project ${projectId} with role ${role} using alternative method`);