/**
* Function to reboot a device in the Cisco Meraki Dashboard.
*
* @param {Object} args - Arguments for the reboot operation.
* @param {string} args.serial - The serial number of the device to reboot.
* @returns {Promise<Object>} - The result of the reboot operation.
*/
const executeFunction = async ({ serial }) => {
const baseUrl = 'https://api.meraki.com/api/v1';
const token = process.env.CISCO_MERAKI_S_PUBLIC_WORKSPACE_API_KEY;
try {
// Construct the URL for the reboot endpoint
const url = `${baseUrl}/devices/${serial}/reboot`;
// Set up headers for the request
const headers = {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
// Perform the fetch request
const response = await fetch(url, {
method: 'POST',
headers
});
// Check if the response was successful
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData);
}
// Parse and return the response data
const data = await response.json();
return data;
} catch (error) {
console.error('Error rebooting device:', error);
return { error: 'An error occurred while rebooting the device.' };
}
};
/**
* Tool configuration for rebooting a device in the Cisco Meraki Dashboard.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'rebootDevice',
description: 'Reboot a device in the Cisco Meraki Dashboard.',
parameters: {
type: 'object',
properties: {
serial: {
type: 'string',
description: 'The serial number of the device to reboot.'
}
},
required: ['serial']
}
}
}
};
export { apiTool };