/**
* Function to unbind a network from a template in the Meraki Dashboard API.
*
* @param {Object} args - Arguments for the unbinding operation.
* @param {string} args.networkId - The ID of the network to unbind.
* @param {boolean} args.retainConfigs - Whether to retain the configurations after unbinding.
* @returns {Promise<Object>} - The result of the unbinding operation.
*/
const executeFunction = async ({ networkId, retainConfigs }) => {
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 unbind operation
const url = `${baseUrl}/networks/${networkId}/unbind`;
// Set up headers for the request
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
// Prepare the request body
const body = JSON.stringify({ retainConfigs });
// 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);
}
// Parse and return the response data
const data = await response.json();
return data;
} catch (error) {
console.error('Error unbinding network:', error);
return { error: 'An error occurred while unbinding the network.' };
}
};
/**
* Tool configuration for unbinding a network from a template in the Meraki Dashboard API.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'unbindNetwork',
description: 'Unbind a network from a template in the Meraki Dashboard API.',
parameters: {
type: 'object',
properties: {
networkId: {
type: 'string',
description: 'The ID of the network to unbind.'
},
retainConfigs: {
type: 'boolean',
description: 'Whether to retain the configurations after unbinding.'
}
},
required: ['networkId', 'retainConfigs']
}
}
}
};
export { apiTool };