UNPKG

n8n-nodes-arubacentral

Version:

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

59 lines (58 loc) 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSite = createSite; const apiRequest_1 = require("../../../../helpers/apiRequest"); const logger_1 = require("../../../../helpers/logger"); const errorHandler_1 = require("../../../../helpers/errorHandler"); /** * Create Site * * POST /central/v2/sites * * @param this The n8n execution context * @returns Formatted API response */ async function createSite() { try { // Get parameters const siteName = this.getNodeParameter('site_name', 0); const locationType = this.getNodeParameter('location_type', 0); // Prepare request body const body = { site_name: siteName, }; if (locationType === 'address') { const address = this.getNodeParameter('address', 0, ''); const city = this.getNodeParameter('city', 0, ''); const state = this.getNodeParameter('state', 0, ''); const country = this.getNodeParameter('country', 0, ''); const zipcode = this.getNodeParameter('zipcode', 0, ''); body.site_address = { address, city, state, country, zipcode, }; } else if (locationType === 'geolocation') { const latitude = this.getNodeParameter('latitude', 0); const longitude = this.getNodeParameter('longitude', 0); body.geolocation = { latitude, longitude, }; } logger_1.logger.debug('monitoring:site:createSite', `Creating site with name: ${siteName}`); // Make API request const endpoint = '/central/v2/sites'; const responseData = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body); logger_1.logger.debug('monitoring:site:createSite', 'Successfully created site'); // Return formatted response return [{ json: responseData }]; } catch (error) { logger_1.logger.error('monitoring:site:createSite:error', { message: error.message }); return errorHandler_1.handleApiError.call(this, error, 'Failed to create site'); } }