UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

41 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateCustomer = updateCustomer; const n8n_workflow_1 = require("n8n-workflow"); const transport_1 = require("../../../transport"); async function updateCustomer(index) { const id = this.getNodeParameter('customerId', index); const { address, businessName, email, firstName, getSms, invoiceCcEmails, lastName, noEmail, notes, notificationEmail, phone, referredBy, } = this.getNodeParameter('updateFields', index); const qs = {}; const requestMethod = 'PUT'; const endpoint = `customers/${id}`; let body = {}; let addressData = address; if (addressData) { addressData = addressData.addressFields; addressData.address_2 = addressData.address2; } body = { ...addressData, business_name: businessName, email, firstname: firstName, get_sms: getSms, invoice_cc_emails: (invoiceCcEmails || []).join(','), lastname: lastName, no_email: noEmail, notes, notification_email: notificationEmail, phone, referred_by: referredBy, }; const responseData = await transport_1.apiRequest.call(this, requestMethod, endpoint, body, qs); if (!responseData.customer) { throw new n8n_workflow_1.NodeApiError(this.getNode(), responseData, { httpCode: '404', message: 'Customer ID not found', }); } return this.helpers.returnJsonArray(responseData.customer); } //# sourceMappingURL=execute.js.map