UNPKG

n8n-nodes-arubacentral

Version:

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

60 lines (59 loc) 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateSite = updateSite; const apiRequest_1 = require("../../../../helpers/apiRequest"); const logger_1 = require("../../../../helpers/logger"); const errorHandler_1 = require("../../../../helpers/errorHandler"); /** * Update Site * * PATCH /central/v2/sites/{site_id} * * @param this The n8n execution context * @returns Formatted API response */ async function updateSite() { try { // Get parameters const siteId = this.getNodeParameter('site_id', 0); 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:updateSite', `Updating site with ID: ${siteId}`); // Make API request const endpoint = `/central/v2/sites/${siteId}`; const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body); logger_1.logger.debug('monitoring:site:updateSite', 'Successfully updated site'); // Return formatted response return [{ json: responseData }]; } catch (error) { logger_1.logger.error('monitoring:site:updateSite:error', { message: error.message }); return errorHandler_1.handleApiError.call(this, error, 'Failed to update site'); } }