n8n-nodes-netbox
Version:
n8n community node for NetBox API integration with comprehensive DCIM, IPAM, Virtualization, Circuits, Wireless, and data center management operations
106 lines (105 loc) • 4.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listDeviceBayTemplates = listDeviceBayTemplates;
exports.getDeviceBayTemplate = getDeviceBayTemplate;
exports.createDeviceBayTemplate = createDeviceBayTemplate;
exports.updateDeviceBayTemplate = updateDeviceBayTemplate;
exports.deleteDeviceBayTemplate = deleteDeviceBayTemplate;
const apiRequest_1 = require("../../../helpers/apiRequest");
const responseFormatter_1 = require("../../../helpers/responseFormatter");
async function listDeviceBayTemplates() {
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 bay templates
if (!queryParams.limit) {
queryParams.limit = 500; // Higher limit for faster pagination
}
responseData = await apiRequest_1.apiRequestAllItems.call(this, 'GET', '/api/dcim/device-bay-templates/', {}, queryParams);
}
else {
const limit = this.getNodeParameter('limit', 0);
queryParams.limit = limit;
const response = await apiRequest_1.apiRequest.call(this, 'GET', '/api/dcim/device-bay-templates/', {}, queryParams);
responseData = response.results || response;
}
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
throw error;
}
}
async function getDeviceBayTemplate() {
try {
const deviceBayTemplateId = this.getNodeParameter('deviceBayTemplateId', 0);
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', `/api/dcim/device-bay-templates/${deviceBayTemplateId}/`);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
throw error;
}
}
async function createDeviceBayTemplate() {
try {
const body = {};
// Required fields
const device_type = this.getNodeParameter('device_type', 0);
const name = this.getNodeParameter('deviceBayTemplateName', 0);
body.device_type = device_type;
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;
}
const responseData = await apiRequest_1.apiRequest.call(this, 'POST', '/api/dcim/device-bay-templates/', body);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
throw error;
}
}
async function updateDeviceBayTemplate() {
try {
const deviceBayTemplateId = this.getNodeParameter('deviceBayTemplateId', 0);
const body = {};
// Optional fields for update
const updateFields = this.getNodeParameter('updateFields', 0, {});
if (updateFields.device_type) {
body.device_type = updateFields.device_type;
}
if (updateFields.name) {
body.name = updateFields.name;
}
if (updateFields.label) {
body.label = updateFields.label;
}
if (updateFields.description) {
body.description = updateFields.description;
}
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', `/api/dcim/device-bay-templates/${deviceBayTemplateId}/`, body);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
throw error;
}
}
async function deleteDeviceBayTemplate() {
try {
const deviceBayTemplateId = this.getNodeParameter('deviceBayTemplateId', 0);
await apiRequest_1.apiRequest.call(this, 'DELETE', `/api/dcim/device-bay-templates/${deviceBayTemplateId}/`);
return [{ json: { success: true } }];
}
catch (error) {
throw error;
}
}