@ixiam/n8n-nodes-civicrm 1.1.24 → 1.1.26

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.
@@ -34,12 +34,7 @@ class CiviCrmApi {
34
34
  this.test = {
35
35
  request: {
36
36
  baseURL: '={{ $credentials.baseUrl }}',
37
- url: '/civicrm/ajax/api4/Contact/get',
38
- method: 'POST',
39
- body: {
40
- limit: 1,
41
- select: ['id'],
42
- },
37
+ url: '',
43
38
  },
44
39
  };
45
40
  }
@@ -143,7 +143,44 @@ class CiviCrm {
143
143
  type: 'number',
144
144
  default: 0,
145
145
  required: true,
146
- displayOptions: { show: { operation: ['get', 'update', 'delete'] } },
146
+ displayOptions: {
147
+ show: {
148
+ operation: ['get', 'update', 'delete'],
149
+ resource: ['contact', 'membership', 'group', 'relationship', 'activity'],
150
+ },
151
+ },
152
+ },
153
+ //
154
+ // CUSTOM API CALL
155
+ //
156
+ {
157
+ displayName: 'Entity',
158
+ name: 'customEntity',
159
+ type: 'string',
160
+ default: 'Contact',
161
+ required: true,
162
+ description: 'CiviCRM API4 entity, for example Contact, Membership, Group, Activity, CustomValue, etc.',
163
+ displayOptions: { show: { resource: ['customApi'] } },
164
+ },
165
+ {
166
+ displayName: 'Action',
167
+ name: 'customAction',
168
+ type: 'string',
169
+ default: 'get',
170
+ required: true,
171
+ description: 'CiviCRM API4 action, for example get, getFields, create, update, delete, getOne, etc.',
172
+ displayOptions: { show: { resource: ['customApi'] } },
173
+ },
174
+ {
175
+ displayName: 'Params (JSON)',
176
+ name: 'customParamsJson',
177
+ type: 'string',
178
+ typeOptions: {
179
+ rows: 4,
180
+ },
181
+ default: '{\n "limit": 25\n}',
182
+ description: 'Raw API4 params JSON passed as-is to CiviCRM. It must be a valid JSON object (no trailing commas).',
183
+ displayOptions: { show: { resource: ['customApi'] } },
147
184
  },
148
185
  //
149
186
  // DYNAMIC FIELDS
@@ -187,6 +224,25 @@ class CiviCrm {
187
224
  const out = [];
188
225
  const resource = this.getNodeParameter('resource', 0);
189
226
  const operation = this.getNodeParameter('operation', 0);
227
+ // Custom API call: generic passthrough to any API4 entity/action
228
+ if (resource === 'customApi') {
229
+ const entity = this.getNodeParameter('customEntity', 0);
230
+ const action = this.getNodeParameter('customAction', 0);
231
+ const paramsJson = this.getNodeParameter('customParamsJson', 0, '');
232
+ let params = {};
233
+ if (paramsJson) {
234
+ try {
235
+ params = JSON.parse(paramsJson);
236
+ }
237
+ catch (error) {
238
+ throw new Error('Invalid JSON in "Params (JSON)"');
239
+ }
240
+ }
241
+ const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/${action}`, params);
242
+ // Return the raw API4 response so advanced users can work with values and metadata
243
+ out.push({ json: res });
244
+ return [out];
245
+ }
190
246
  const entity = ENTITY_MAP[resource];
191
247
  for (let i = 0; i < items.length; i++) {
192
248
  const emailLocationParam = this.getNodeParameter('emailLocation', i, 'Work');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ixiam/n8n-nodes-civicrm",
3
- "version": "1.1.24",
3
+ "version": "1.1.26",
4
4
  "description": "Full-featured CiviCRM API v4 integration for n8n with support for Contacts, Memberships, Groups, Relationships, Activities and structured sub-entities like Email, Phone, and Address.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -40,12 +40,7 @@ export class CiviCrmApi implements ICredentialType {
40
40
  test: ICredentialTestRequest = {
41
41
  request: {
42
42
  baseURL: '={{ $credentials.baseUrl }}',
43
- url: '/civicrm/ajax/api4/Contact/get',
44
- method: 'POST',
45
- body: {
46
- limit: 1,
47
- select: ['id'],
48
- },
43
+ url: '',
49
44
  },
50
45
  };
51
46
  }
@@ -21,11 +21,12 @@ type Resource =
21
21
  | 'membership'
22
22
  | 'group'
23
23
  | 'relationship'
24
- | 'activity';
24
+ | 'activity'
25
+ | 'customApi';
25
26
 
26
27
  type Operation = 'get' | 'getMany' | 'create' | 'update' | 'delete';
27
28
 
28
- const ENTITY_MAP: Record<Resource, string> = {
29
+ const ENTITY_MAP: Record<Exclude<Resource, 'customApi'>, string> = {
29
30
  contact: 'Contact',
30
31
  membership: 'Membership',
31
32
  group: 'Group',
@@ -176,7 +177,48 @@ export class CiviCrm implements INodeType {
176
177
  type: 'number',
177
178
  default: 0,
178
179
  required: true,
179
- displayOptions: { show: { operation: ['get', 'update', 'delete'] } },
180
+ displayOptions: {
181
+ show: {
182
+ operation: ['get', 'update', 'delete'],
183
+ resource: ['contact', 'membership', 'group', 'relationship', 'activity'],
184
+ },
185
+ },
186
+ },
187
+
188
+ //
189
+ // CUSTOM API CALL
190
+ //
191
+ {
192
+ displayName: 'Entity',
193
+ name: 'customEntity',
194
+ type: 'string',
195
+ default: 'Contact',
196
+ required: true,
197
+ description:
198
+ 'CiviCRM API4 entity, for example Contact, Membership, Group, Activity, CustomValue, etc.',
199
+ displayOptions: { show: { resource: ['customApi'] } },
200
+ },
201
+ {
202
+ displayName: 'Action',
203
+ name: 'customAction',
204
+ type: 'string',
205
+ default: 'get',
206
+ required: true,
207
+ description:
208
+ 'CiviCRM API4 action, for example get, getFields, create, update, delete, getOne, etc.',
209
+ displayOptions: { show: { resource: ['customApi'] } },
210
+ },
211
+ {
212
+ displayName: 'Params (JSON)',
213
+ name: 'customParamsJson',
214
+ type: 'string',
215
+ typeOptions: {
216
+ rows: 4,
217
+ },
218
+ default: '{\n "limit": 25\n}',
219
+ description:
220
+ 'Raw API4 params JSON passed as-is to CiviCRM. It must be a valid JSON object (no trailing commas).',
221
+ displayOptions: { show: { resource: ['customApi'] } },
180
222
  },
181
223
 
182
224
  //
@@ -230,6 +272,34 @@ export class CiviCrm implements INodeType {
230
272
 
231
273
  const resource = this.getNodeParameter('resource', 0) as Resource;
232
274
  const operation = this.getNodeParameter('operation', 0) as Operation;
275
+
276
+ // Custom API call: generic passthrough to any API4 entity/action
277
+ if (resource === 'customApi') {
278
+ const entity = this.getNodeParameter('customEntity', 0) as string;
279
+ const action = this.getNodeParameter('customAction', 0) as string;
280
+ const paramsJson = this.getNodeParameter('customParamsJson', 0, '') as string;
281
+
282
+ let params: Record<string, unknown> = {};
283
+ if (paramsJson) {
284
+ try {
285
+ params = JSON.parse(paramsJson);
286
+ } catch (error) {
287
+ throw new Error('Invalid JSON in "Params (JSON)"');
288
+ }
289
+ }
290
+
291
+ const res = await civicrmApiRequest.call(
292
+ this,
293
+ 'POST',
294
+ `/civicrm/ajax/api4/${entity}/${action}`,
295
+ params,
296
+ );
297
+
298
+ // Return the raw API4 response so advanced users can work with values and metadata
299
+ out.push({ json: res as IDataObject });
300
+ return [out];
301
+ }
302
+
233
303
  const entity = ENTITY_MAP[resource];
234
304
 
235
305
  for (let i = 0; i < items.length; i++) {