/**
* Function to remove a device from a Meraki network.
*
* @param {Object} args - Arguments for the device removal.
* @param {string} args.networkId - The ID of the network from which to remove the device.
* @param {string} args.serial - The serial number of the device to be removed.
* @returns {Promise<Object>} - The result of the device removal operation.
*/
const executeFunction = async ({ networkId, 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 request
const url = `${baseUrl}/networks/${networkId}/devices/remove`;
// Set up headers for the request
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
};
// Prepare the body of the request
const body = JSON.stringify({ serial });
// Perform the fetch request
const response = await fetch(url, {
method: 'POST',
headers,
body
});
// Check if the response was successful
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData);
}
// Return the response data
return { status: response.status, message: 'Device removed successfully.' };
} catch (error) {
console.error('Error removing device:', error);
return { error: 'An error occurred while removing the device.' };
}
};
/**
* Tool configuration for removing a device from a Meraki network.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'removeNetworkDevices',
description: 'Remove a single device from a Meraki network.',
parameters: {
type: 'object',
properties: {
networkId: {
type: 'string',
description: 'The ID of the network from which to remove the device.'
},
serial: {
type: 'string',
description: 'The serial number of the device to be removed.'
}
},
required: ['networkId', 'serial']
}
}
}
};
export { apiTool };