UNPKG

n8n-nodes-netbox

Version:

n8n community node for NetBox API integration with comprehensive DCIM, IPAM, Virtualization, Circuits, Wireless, and data center management operations

124 lines (123 loc) 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listDeviceBays = listDeviceBays; exports.getDeviceBay = getDeviceBay; exports.createDeviceBay = createDeviceBay; exports.updateDeviceBay = updateDeviceBay; exports.deleteDeviceBay = deleteDeviceBay; const apiRequest_1 = require("../../../helpers/apiRequest"); const responseFormatter_1 = require("../../../helpers/responseFormatter"); async function listDeviceBays() { try { // Get pagination parameters const returnAll = this.getNodeParameter('returnAll', 0); // Get filters - this will include all the advanced filter fields const filters = this.getNodeParameter('filters', 0, {}); // Prepare query parameters const queryParams = { ...filters }; let responseData; if (returnAll) { // Add higher limit to the first query when listing device bays if (!queryParams.limit) { queryParams.limit = 500; // Higher limit for faster pagination } responseData = await apiRequest_1.apiRequestAllItems.call(this, 'GET', '/api/dcim/device-bays/', {}, queryParams); } else { const limit = this.getNodeParameter('limit', 0); queryParams.limit = limit; const response = await apiRequest_1.apiRequest.call(this, 'GET', '/api/dcim/device-bays/', {}, queryParams); responseData = response.results || response; } return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function getDeviceBay() { try { const deviceBayId = this.getNodeParameter('deviceBayId', 0); const responseData = await apiRequest_1.apiRequest.call(this, 'GET', `/api/dcim/device-bays/${deviceBayId}/`); return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function createDeviceBay() { try { const body = {}; // Required fields const device = this.getNodeParameter('device', 0); const name = this.getNodeParameter('deviceBayName', 0); body.device = device; body.name = name; // Optional fields const additionalFields = this.getNodeParameter('additionalFields', 0, {}); if (additionalFields.label) { body.label = additionalFields.label; } if (additionalFields.description) { body.description = additionalFields.description; } if (additionalFields.installed_device) { body.installed_device = additionalFields.installed_device; } if (additionalFields.tags) { body.tags = additionalFields.tags; } if (additionalFields.custom_fields) { body.custom_fields = JSON.parse(additionalFields.custom_fields); } const responseData = await apiRequest_1.apiRequest.call(this, 'POST', '/api/dcim/device-bays/', body); return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function updateDeviceBay() { try { const deviceBayId = this.getNodeParameter('deviceBayId', 0); const body = {}; // Optional fields for update const updateFields = this.getNodeParameter('updateFields', 0, {}); if (updateFields.device) { body.device = updateFields.device; } if (updateFields.name) { body.name = updateFields.name; } if (updateFields.label) { body.label = updateFields.label; } if (updateFields.description) { body.description = updateFields.description; } if (updateFields.installed_device) { body.installed_device = updateFields.installed_device; } if (updateFields.tags) { body.tags = updateFields.tags; } if (updateFields.custom_fields) { body.custom_fields = JSON.parse(updateFields.custom_fields); } const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', `/api/dcim/device-bays/${deviceBayId}/`, body); return responseFormatter_1.formatResponse.call(this, responseData); } catch (error) { throw error; } } async function deleteDeviceBay() { try { const deviceBayId = this.getNodeParameter('deviceBayId', 0); await apiRequest_1.apiRequest.call(this, 'DELETE', `/api/dcim/device-bays/${deviceBayId}/`); return [{ json: { success: true } }]; } catch (error) { throw error; } }