UNPKG

n8n-nodes-arubacentral

Version:

n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities

275 lines (240 loc) 7.77 kB
# Steps to Implement Additional API Methods in the Aruba Central Node Here's a comprehensive guide for implementing new API methods in your Aruba Central n8n node: ## 1. Research & Planning 1. **Review the API documentation** - Understand the endpoint structure, parameters, and response format - Identify authentication requirements - Note any rate limiting or special considerations 2. **Determine the logical grouping** - Decide which domain, resource, and operation the new method belongs to - Follow the existing pattern of `domain/resource/operation` ## 2. Create or Update Type Definitions 1. **Update or create interface files** - Add new interfaces in `monitoring.types.ts` (or other domain types) - Define request parameter interfaces - Define response data interfaces - Example: ```typescript export interface NewResourceData { id?: string; name?: string; status?: string; // other properties } ``` 2. **Update filter/parameter types** - Add new parameter types if needed - Extend existing interfaces if adding optional parameters ## 3. Implement the Method Function 1. **Create or update the method file** - If adding to an existing resource: add the function to the existing file - If creating a new resource: create a new file in the appropriate domain folder - Location example: `/methods/monitoring/newresource/newresource.methods.ts` 2. **Implement the method function** - Follow the established pattern with proper typing - Include comprehensive error handling - Add detailed logging for easier troubleshooting - Example: ```typescript export async function newOperation( this: IExecuteFunctions, ): Promise<INodeExecutionData[]> { console.log('Starting newOperation'); try { // Extract parameters const paramA = this.getNodeParameter('paramA', 0) as string; // Build query/request parameters const params = { key: paramA }; // Make API request const response = await apiRequest.call( this, 'GET', '/endpoint/path', {}, params ); // Format & return response return formatResponse(response); } catch (error) { console.log('ERROR in newOperation:', error); throw error; } } ``` ## 4. Update UI Descriptions 1. **Update the operation options** - Add your new operation to the appropriate resource in `monitoring.descriptions.ts` - Example for `apOperations`: ```typescript options: [ // Existing options { name: 'New Operation', value: 'newOperation', description: 'Description of what this operation does', action: 'Perform new operation', }, ], ``` 2. **Create input fields for the operation** - Define all required and optional parameters with appropriate types - Use display options to show/hide fields based on operation selection - Example: ```typescript { displayName: 'Parameter Name', name: 'paramName', type: 'string', default: '', required: true, description: 'Description of the parameter', displayOptions: { show: { domain: ['monitoring'], resource: ['resourceName'], operation: ['newOperation'], }, }, }, ``` 3. **Create option collections for complex parameters** - Group related options using collection type - Example: ```typescript { displayName: 'Additional Options', name: 'additionalOptions', type: 'collection', placeholder: 'Add Option', default: {}, displayOptions: { show: { domain: ['monitoring'], resource: ['resourceName'], operation: ['newOperation'], }, }, options: [ { displayName: 'Filter by Status', name: 'status', type: 'options', options: [ { name: 'Active', value: 'active' }, { name: 'Inactive', value: 'inactive' }, ], default: '', description: 'Filter results by status', }, // More options ], }, ``` ## 5. Register the Methods in the Operation Handler 1. **Update the executeOperation.ts file** - Import the new method function(s) - Add the functions to the appropriate handlers object - Example: ```typescript import { newOperation } from '../methods/monitoring/newresource/newresource.methods'; const handlers = { monitoring: { newresource: { newOperation: newOperation, }, // Existing resources }, }; ``` ## 6. Build and Test 1. **Build the node** - Run the build command to compile TypeScript - Check for any type errors or compilation issues 2. **Test the new operation** - Try the operation in n8n UI - Test with various parameter combinations - Verify error handling by intentionally using invalid parameters - Check the logs for proper execution flow 3. **Debug if necessary** - Add more logging statements to isolate issues - Double-check API parameter formatting - Verify authentication is working correctly ## Example Workflow for Adding a New "List Clients" Operation 1. **Research**: Understand how to list clients in Aruba Central API 2. **Update Types**: ```typescript // monitoring.types.ts export interface Client { mac_address?: string; ip_address?: string; hostname?: string; connected_to?: string; signal_strength?: number; // other properties } ``` 3. **Implement Method**: ```typescript // Create clients.methods.ts or add to existing file export async function listClients(this: IExecuteFunctions): Promise<INodeExecutionData[]> { console.log('Starting listClients operation'); try { // Extract parameters and make API call // ... return formatResponse(response, 'clients'); } catch (error) { console.log('ERROR in listClients:', error); throw error; } } ``` 4. **Update Descriptions**: ```typescript // Add to monitoring.descriptions.ts export const clientOperations: INodeProperties = { displayName: 'Operation', name: 'operation', type: 'options', displayOptions: { show: { domain: ['monitoring'], resource: ['clients'], }, }, options: [ { name: 'List Clients', value: 'list', description: 'Get a list of connected clients', action: 'List clients', }, ], default: 'list', }; // Add client fields export const clientFields: INodeProperties[] = [ // Fields definition ]; // Add to monitoringProperties export const monitoringProperties: INodeProperties[] = [ monitoringResources, apOperations, clientOperations, // Add the new operations // ...existing properties ...clientFields, // Add the new fields ]; ``` 5. **Register in Operation Handler**: ```typescript import { listClients } from '../methods/monitoring/clients/clients.methods'; const handlers = { monitoring: { clients: { list: listClients, }, // Existing resources }, }; ``` 6. **Build and Test** the new operation By following these steps consistently, you can efficiently extend the node with new API methods while maintaining code quality and ensuring a seamless user experience.