/**
* Function to list organizations that the user has privileges on in the Meraki Dashboard.
*
* @param {Object} args - Arguments for the organization listing.
* @param {number} [args.perPage=9000] - The number of entries per page returned. Acceptable range is 3 - 9000. Default is 9000.
* @param {string} [args.startingAfter] - A token used by the server to indicate the start of the page.
* @param {string} [args.endingBefore] - A token used by the server to indicate the end of the page.
* @returns {Promise<Array>} - The list of organizations.
*/
const executeFunction = async ({ perPage = 9000, startingAfter, endingBefore }) => {
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 request
const url = new URL(`${baseUrl}/organizations`);
if (perPage) url.searchParams.append('perPage', perPage);
if (startingAfter) url.searchParams.append('startingAfter', startingAfter);
if (endingBefore) url.searchParams.append('endingBefore', endingBefore);
// Set up headers for the request
const headers = {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
// Perform the fetch request
const response = await fetch(url.toString(), {
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 fetching organizations:', error);
return { error: 'An error occurred while fetching organizations.' };
}
};
/**
* Tool configuration for listing organizations in the Meraki Dashboard.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'getOrganizations',
description: 'List the organizations that the user has privileges on.',
parameters: {
type: 'object',
properties: {
perPage: {
type: 'integer',
description: 'The number of entries per page returned. Acceptable range is 3 - 9000. Default is 9000.'
},
startingAfter: {
type: 'string',
description: 'A token used by the server to indicate the start of the page.'
},
endingBefore: {
type: 'string',
description: 'A token used by the server to indicate the end of the page.'
}
}
}
}
}
};
export { apiTool };