n8n-nodes-netbox
Version:
n8n community node for NetBox API integration with comprehensive DCIM, IPAM, Virtualization, Circuits, Wireless, and data center management operations
87 lines (86 loc) • 3.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listContactRoles = listContactRoles;
exports.getContactRole = getContactRole;
exports.createContactRole = createContactRole;
exports.updateContactRole = updateContactRole;
exports.deleteContactRole = deleteContactRole;
const apiRequest_1 = require("../../../helpers/apiRequest");
const responseFormatter_1 = require("../../../helpers/responseFormatter");
async function listContactRoles() {
const returnAll = this.getNodeParameter('returnAll', 0);
const filters = this.getNodeParameter('filters', 0, {});
const qs = {};
Object.assign(qs, filters);
if (returnAll) {
const response = await apiRequest_1.apiRequestAllItems.call(this, 'GET', '/api/tenancy/contact-roles/', {}, qs);
return responseFormatter_1.formatResponse.call(this, response);
}
else {
const limit = this.getNodeParameter('limit', 0);
qs.limit = limit;
const response = await apiRequest_1.apiRequest.call(this, 'GET', '/api/tenancy/contact-roles/', {}, qs);
return responseFormatter_1.formatResponse.call(this, response);
}
}
async function getContactRole() {
const contactRoleId = this.getNodeParameter('id', 0);
try {
const endpoint = `/api/tenancy/contact-roles/${contactRoleId}/`;
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
throw new Error(`Failed to get contact role: ${error.message}`);
}
}
async function createContactRole() {
const name = this.getNodeParameter('contactRoleName', 0);
const slug = this.getNodeParameter('slug', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0);
const body = {
name,
slug,
};
try {
// Add all additional fields to the request body
Object.assign(body, additionalFields);
const endpoint = '/api/tenancy/contact-roles/';
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
throw new Error(`Failed to create contact role: ${error.message}`);
}
}
async function updateContactRole() {
const contactRoleId = this.getNodeParameter('id', 0);
const name = this.getNodeParameter('contactRoleName', 0);
const slug = this.getNodeParameter('slug', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0);
const body = {
name,
slug,
};
try {
// Add all additional fields to the request body
Object.assign(body, additionalFields);
const endpoint = `/api/tenancy/contact-roles/${contactRoleId}/`;
const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body);
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
throw new Error(`Failed to update contact role: ${error.message}`);
}
}
async function deleteContactRole() {
const contactRoleId = this.getNodeParameter('id', 0);
try {
const endpoint = `/api/tenancy/contact-roles/${contactRoleId}/`;
await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint);
return [{ json: { success: true } }];
}
catch (error) {
throw new Error(`Failed to delete contact role: ${error.message}`);
}
}