57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
|
|
// src/services/glpiService.js
|
||
|
|
|
||
|
|
const axios = require('axios');
|
||
|
|
const { GLPI_URL, GLPI_APP_TOKEN, GLPI_USER_TOKEN } = process.env;
|
||
|
|
|
||
|
|
// Function to create a ticket in GLPI
|
||
|
|
const createTicketInGLPI = async (ticketData) => {
|
||
|
|
try {
|
||
|
|
const response = await axios.post(`${GLPI_URL}/ticket`, ticketData, {
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
'App-Token': GLPI_APP_TOKEN,
|
||
|
|
'Authorization': `Bearer ${GLPI_USER_TOKEN}`
|
||
|
|
}
|
||
|
|
});
|
||
|
|
return response.data;
|
||
|
|
} catch (error) {
|
||
|
|
throw new Error(`Error creating ticket in GLPI: ${error.message}`);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// Function to update a ticket in GLPI
|
||
|
|
const updateTicketInGLPI = async (ticketId, ticketData) => {
|
||
|
|
try {
|
||
|
|
const response = await axios.put(`${GLPI_URL}/ticket/${ticketId}`, ticketData, {
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
'App-Token': GLPI_APP_TOKEN,
|
||
|
|
'Authorization': `Bearer ${GLPI_USER_TOKEN}`
|
||
|
|
}
|
||
|
|
});
|
||
|
|
return response.data;
|
||
|
|
} catch (error) {
|
||
|
|
throw new Error(`Error updating ticket in GLPI: ${error.message}`);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// Function to fetch ticket details from GLPI
|
||
|
|
const getTicketFromGLPI = async (ticketId) => {
|
||
|
|
try {
|
||
|
|
const response = await axios.get(`${GLPI_URL}/ticket/${ticketId}`, {
|
||
|
|
headers: {
|
||
|
|
'App-Token': GLPI_APP_TOKEN,
|
||
|
|
'Authorization': `Bearer ${GLPI_USER_TOKEN}`
|
||
|
|
}
|
||
|
|
});
|
||
|
|
return response.data;
|
||
|
|
} catch (error) {
|
||
|
|
throw new Error(`Error fetching ticket from GLPI: ${error.message}`);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
createTicketInGLPI,
|
||
|
|
updateTicketInGLPI,
|
||
|
|
getTicketFromGLPI
|
||
|
|
};
|