n8n-nodes-msdyn365bc
Version:
An n8n integration node for Microsoft Dynamics 365 Business Central
81 lines • 3.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BusinessCentral = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class BusinessCentral {
constructor() {
this.description = {
displayName: 'Business Central',
subtitle: '={{ $parameter["operation"] + ": " + $parameter["resource"] }}',
name: 'businessCentral',
icon: 'file:businesscentral.svg',
group: ['transform'],
version: 1,
description: 'Interact with Microsoft Dynamics 365 Business Central',
defaults: { name: 'Business Central' },
inputs: ["main"],
outputs: ["main"],
credentials: [{ name: 'businessCentralApi', required: true }],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [{ name: 'Web Services', value: 'webServices' }],
default: 'webServices',
},
{
displayName: 'Service Name',
name: 'serviceName',
type: 'string',
default: 'workflowCustomers',
description: 'Service path used in the API URL (e.g. workflowCustomers)',
displayOptions: {
show: {
operation: ['webServices'],
},
},
required: true,
},
],
};
}
async execute() {
var _a, _b;
const returnData = [];
const operation = this.getNodeParameter('operation', 0);
if (operation === 'webServices') {
const serviceName = this.getNodeParameter('serviceName', 0);
const credentials = await this.getCredentials('businessCentralApi');
const tenantId = credentials.tenantId;
const environment = (credentials.environmentName || credentials.environment);
const companyId = credentials.companyId;
const url = `https://api.businesscentral.dynamics.com/v2.0/${tenantId}/${environment}/ODataV4/Company('${companyId}')/${serviceName}`;
let lastError;
try {
const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'businessCentralApi', { method: 'GET', url, json: true });
if (responseData.value && Array.isArray(responseData.value)) {
for (const customer of responseData.value) {
returnData.push({ json: customer });
}
return [returnData];
}
}
catch (error) {
console.log('Attempt failed:', error.message);
lastError = error;
}
if (lastError) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), lastError, {
message: 'All API endpoint attempts failed',
description: 'Tried multiple endpoint formats without success',
httpCode: ((_b = (_a = lastError.response) === null || _a === void 0 ? void 0 : _a.status) === null || _b === void 0 ? void 0 : _b.toString()) || 'Unknown',
});
}
}
return [returnData];
}
}
exports.BusinessCentral = BusinessCentral;
//# sourceMappingURL=BusinessCentral.node.js.map