/**
* Function to update a network in the Cisco Meraki Dashboard.
*
* @param {Object} args - Arguments for the network update.
* @param {string} args.networkId - The ID of the network to update.
* @param {string} args.name - The new name for the network.
* @param {string} args.timeZone - The time zone for the network.
* @param {Array<string>} args.tags - An array of tags for the network.
* @param {string} args.enrollmentString - The enrollment string for the network.
* @param {string} args.notes - Additional notes for the network.
* @returns {Promise<Object>} - The result of the network update.
*/
const executeFunction = async ({ networkId, name, timeZone, tags, enrollmentString, notes }) => {
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 network update
const url = `${baseUrl}/networks/${networkId}`;
// Set up the request body
const body = JSON.stringify({
name,
timeZone,
tags,
enrollmentString,
notes
});
// Set up headers for the request
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
// Perform the fetch request
const response = await fetch(url, {
method: 'PUT',
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 updating the network:', error);
return { error: 'An error occurred while updating the network.' };
}
};
/**
* Tool configuration for updating a network in the Cisco Meraki Dashboard.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'updateNetwork',
description: 'Update a network in the Cisco Meraki Dashboard.',
parameters: {
type: 'object',
properties: {
networkId: {
type: 'string',
description: 'The ID of the network to update.'
},
name: {
type: 'string',
description: 'The new name for the network.'
},
timeZone: {
type: 'string',
description: 'The time zone for the network.'
},
tags: {
type: 'array',
items: {
type: 'string'
},
description: 'An array of tags for the network.'
},
enrollmentString: {
type: 'string',
description: 'The enrollment string for the network.'
},
notes: {
type: 'string',
description: 'Additional notes for the network.'
}
},
required: ['networkId', 'name', 'timeZone']
}
}
}
};
export { apiTool };