/**
* Function to update the policy assigned to a client on a Meraki network.
*
* @param {Object} args - Arguments for updating the client policy.
* @param {string} args.networkId - The ID of the network.
* @param {string} args.clientId - The ID of the client.
* @param {string} args.devicePolicy - The new device policy to assign to the client.
* @param {string} args.groupPolicyId - The ID of the group policy to assign to the client.
* @returns {Promise<Object>} - The result of the policy update operation.
*/
const executeFunction = async ({ networkId, clientId, devicePolicy, groupPolicyId }) => {
const baseUrl = 'https://api.meraki.com/api/v1';
const token = process.env.CISCO_MERAKI_S_PUBLIC_WORKSPACE_API_KEY;
try {
const url = `${baseUrl}/networks/${networkId}/clients/${clientId}/policy`;
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
const body = JSON.stringify({
devicePolicy,
groupPolicyId
});
const response = await fetch(url, {
method: 'PUT',
headers,
body
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error updating client policy:', error);
return { error: 'An error occurred while updating the client policy.' };
}
};
/**
* Tool configuration for updating the client policy on a Meraki network.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'updateNetworkClientPolicy',
description: 'Update the policy assigned to a client on a Meraki network.',
parameters: {
type: 'object',
properties: {
networkId: {
type: 'string',
description: 'The ID of the network.'
},
clientId: {
type: 'string',
description: 'The ID of the client.'
},
devicePolicy: {
type: 'string',
description: 'The new device policy to assign to the client.'
},
groupPolicyId: {
type: 'string',
description: 'The ID of the group policy to assign to the client.'
}
},
required: ['networkId', 'clientId', 'devicePolicy', 'groupPolicyId']
}
}
}
};
export { apiTool };