/**
* Function to get the policy assigned to a client on the network.
*
* @param {Object} args - Arguments for the client policy retrieval.
* @param {string} args.networkId - The ID of the network.
* @param {string} args.clientId - The ID of the client.
* @returns {Promise<Object>} - The result of the client policy retrieval.
*/
const executeFunction = async ({ networkId, clientId }) => {
const baseUrl = 'https://api.meraki.com/api/v1';
const token = process.env.CISCO_MERAKI_S_PUBLIC_WORKSPACE_API_KEY;
try {
// Construct the URL with path parameters
const url = `${baseUrl}/networks/${networkId}/clients/${clientId}/policy`;
// Set up headers for the request
const headers = {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
// Perform the fetch request
const response = await fetch(url, {
method: 'GET',
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 retrieving client policy:', error);
return { error: 'An error occurred while retrieving the client policy.' };
}
};
/**
* Tool configuration for retrieving client policy on the Meraki Dashboard API.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'getNetworkClientPolicy',
description: 'Retrieve the policy assigned to a client on the network.',
parameters: {
type: 'object',
properties: {
networkId: {
type: 'string',
description: 'The ID of the network.'
},
clientId: {
type: 'string',
description: 'The ID of the client.'
}
},
required: ['networkId', 'clientId']
}
}
}
};
export { apiTool };