n8n-nodes-netbox
Version:
n8n community node for NetBox API integration with comprehensive DCIM, IPAM, and data center management operations
79 lines (78 loc) • 3.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listConfigContexts = listConfigContexts;
exports.getConfigContext = getConfigContext;
exports.createConfigContext = createConfigContext;
exports.updateConfigContext = updateConfigContext;
exports.deleteConfigContext = deleteConfigContext;
const apiRequest_1 = require("../../../helpers/apiRequest");
const responseFormatter_1 = require("../../../helpers/responseFormatter");
async function listConfigContexts() {
const filters = this.getNodeParameter('filter', 0, {}); // Change this line
const endpoint = '/api/extras/config-contexts/';
const response = await apiRequest_1.apiRequestAllItems.call(this, 'GET', endpoint, {}, filters);
return responseFormatter_1.formatResponse.call(this, response);
}
async function getConfigContext() {
const configContextId = this.getNodeParameter('configContextId', 0);
const endpoint = `/api/extras/config-contexts/${configContextId}/`;
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint);
return responseFormatter_1.formatResponse.call(this, response);
}
async function createConfigContext() {
const name = this.getNodeParameter('name', 0);
const dataJson = this.getNodeParameter('data', 0);
const weight = this.getNodeParameter('weight', 0, 1000);
const isActive = this.getNodeParameter('is_active', 0, true);
const description = this.getNodeParameter('description', 0, '');
let data;
try {
data = JSON.parse(dataJson);
}
catch (error) {
throw new Error('Invalid JSON in data field');
}
const body = {
name,
data,
weight,
is_active: isActive,
};
if (description)
body.description = description;
const endpoint = '/api/extras/config-contexts/';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body);
return responseFormatter_1.formatResponse.call(this, response);
}
async function updateConfigContext() {
const configContextId = this.getNodeParameter('configContextId', 0);
const name = this.getNodeParameter('name', 0);
const dataJson = this.getNodeParameter('data', 0);
const weight = this.getNodeParameter('weight', 0, 1000);
const isActive = this.getNodeParameter('is_active', 0, true);
const description = this.getNodeParameter('description', 0, '');
let data;
try {
data = JSON.parse(dataJson);
}
catch (error) {
throw new Error('Invalid JSON in data field');
}
const body = {
name,
data,
weight,
is_active: isActive,
};
if (description)
body.description = description;
const endpoint = `/api/extras/config-contexts/${configContextId}/`;
const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body);
return responseFormatter_1.formatResponse.call(this, response);
}
async function deleteConfigContext() {
const configContextId = this.getNodeParameter('configContextId', 0);
const endpoint = `/api/extras/config-contexts/${configContextId}/`;
await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint);
return [{ json: { success: true } }];
}