n8n-nodes-mailchimp-cmdesign 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -142,9 +142,23 @@ class MailchimpCmNode {
142
142
  const server = credentials.serverPrefix;
143
143
  const apiUrl = `https://${server}.api.mailchimp.com/3.0`;
144
144
  const action = this.getNodeParameter('action', 0);
145
+ console.log('>>> Action:', action);
146
+ console.log('>>> Input data length:', this.getInputData().length);
145
147
  if (action === 'createUpdateSubscriber') {
146
- const response = await createUpdateSubscriber_1.createUpdateSubscriber.call(this, apiUrl, apiKey);
147
- returnData.push({ json: response });
148
+ try {
149
+ // Debug: ellenőrizzük a paramétereket
150
+ const listId = this.getNodeParameter('listId', 0);
151
+ const mapping = this.getNodeParameter('subscriberFieldMapping', 0);
152
+ console.log('>>> List ID:', listId);
153
+ console.log('>>> Field mapping:', JSON.stringify(mapping, null, 2));
154
+ const response = await createUpdateSubscriber_1.createUpdateSubscriber.call(this, apiUrl, apiKey);
155
+ console.log('>>> API Response:', response);
156
+ returnData.push({ json: response });
157
+ }
158
+ catch (error) {
159
+ console.error('>>> Error in createUpdateSubscriber:', error);
160
+ throw error;
161
+ }
148
162
  }
149
163
  return [returnData];
150
164
  }
@@ -3,30 +3,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createUpdateSubscriber = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
5
  async function createUpdateSubscriber(apiUrl, apiKey) {
6
+ var _a;
6
7
  const listId = this.getNodeParameter('listId', 0);
8
+ const createIfNotExists = this.getNodeParameter('createIfNotExists', 0);
9
+ // Field mapping lekérése
7
10
  const mapping = this.getNodeParameter('subscriberFieldMapping', 0);
8
11
  const items = this.getInputData();
9
- const members = items.map((item) => {
10
- var _a;
11
- const email = this.getNodeParameter('email', 0, item.index);
12
+ const members = [];
13
+ // Minden input item feldolgozása
14
+ for (let i = 0; i < items.length; i++) {
15
+ const item = items[i];
16
+ // Email lekérése - az i indexet használjuk, nem item.index-et
17
+ const email = this.getNodeParameter('email', i);
18
+ if (!email) {
19
+ throw new Error(`Email is required for item ${i}`);
20
+ }
21
+ // Merge fields összeállítása a field mapping alapján
12
22
  const mergeFields = {};
13
23
  if (((_a = mapping === null || mapping === void 0 ? void 0 : mapping.subscriberFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
14
24
  for (const field of mapping.subscriberFields) {
25
+ // Az aktuális item JSON-jából vesszük az értéket
15
26
  const value = item.json[field.subscriberIncomingKey];
16
27
  if (value !== undefined && value !== null && String(value).trim() !== '') {
17
- mergeFields[field.mailChimpField] = String(value);
28
+ mergeFields[field.mailChimpField] = String(value).trim();
18
29
  }
19
30
  }
20
31
  }
21
- return {
32
+ members.push({
22
33
  email_address: email,
23
34
  status: 'subscribed',
24
35
  merge_fields: mergeFields,
25
- };
26
- });
36
+ });
37
+ }
38
+ // Batch operations használata
27
39
  const body = {
28
40
  members,
29
- update_existing: true,
41
+ update_existing: createIfNotExists,
30
42
  };
31
43
  try {
32
44
  const response = await this.helpers.httpRequest({
@@ -34,6 +46,7 @@ async function createUpdateSubscriber(apiUrl, apiKey) {
34
46
  url: `${apiUrl}/lists/${listId}`,
35
47
  headers: {
36
48
  Authorization: `apikey ${apiKey}`,
49
+ 'Content-Type': 'application/json',
37
50
  },
38
51
  body,
39
52
  json: true,
@@ -41,8 +54,9 @@ async function createUpdateSubscriber(apiUrl, apiKey) {
41
54
  return response;
42
55
  }
43
56
  catch (error) {
57
+ console.error('Mailchimp API Error:', error);
44
58
  throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
45
- message: 'Hiba történt az előfizetők létrehozása/frissítése közben.',
59
+ message: `Hiba történt az előfizetők létrehozása/frissítése közben: ${(error === null || error === void 0 ? void 0 : error.message) || 'Ismeretlen hiba'}`,
46
60
  });
47
61
  }
48
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-mailchimp-cmdesign",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "n8n node to interact with Mailchimp API",
5
5
  "main": "index.js",
6
6
  "scripts": {