/**
* Function to claim devices into a Meraki network.
*
* @param {Object} args - Arguments for claiming devices.
* @param {Array<string>} args.serials - An array of serial numbers of the devices to claim.
* @param {Array<Object>} args.detailsByDevice - An array of objects containing device details.
* @param {string} args.networkId - The ID of the network to which the devices will be claimed.
* @param {boolean} [args.addAtomically=true] - Whether to claim devices atomically.
* @returns {Promise<Object>} - The result of the claim operation.
*/
const executeFunction = async ({ serials, detailsByDevice, networkId, addAtomically = true }) => {
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 claim devices endpoint
const url = `${baseUrl}/networks/${networkId}/devices/claim?addAtomically=${addAtomically}`;
// Set up headers for the request
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
// Prepare the body of the request
const body = JSON.stringify({
serials,
detailsByDevice
});
// 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 claiming devices:', error);
return { error: 'An error occurred while claiming devices.' };
}
};
/**
* Tool configuration for claiming devices into a Meraki network.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'claimNetworkDevices',
description: 'Claim devices into a Meraki network.',
parameters: {
type: 'object',
properties: {
serials: {
type: 'array',
items: {
type: 'string'
},
description: 'An array of serial numbers of the devices to claim.'
},
detailsByDevice: {
type: 'array',
items: {
type: 'object',
properties: {
serial: {
type: 'string',
description: 'The serial number of the device.'
},
details: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'The name of the detail.'
},
value: {
type: 'string',
description: 'The value of the detail.'
}
},
required: ['name', 'value']
},
description: 'An array of details for the device.'
}
},
required: ['serial', 'details']
},
description: 'An array of objects containing device details.'
},
networkId: {
type: 'string',
description: 'The ID of the network to which the devices will be claimed.'
},
addAtomically: {
type: 'boolean',
description: 'Whether to claim devices atomically.'
}
},
required: ['serials', 'networkId']
}
}
}
};
export { apiTool };