@worktables/n8n-nodes-worktables 12.2.5 → 12.2.7

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.
@@ -419,6 +419,14 @@ class Worktables {
419
419
  description: 'Enter the query to run',
420
420
  displayOptions: { show: { resource: ['query'] } },
421
421
  },
422
+ {
423
+ displayName: 'API Version',
424
+ name: 'apiVersion',
425
+ type: 'string',
426
+ default: '2025-01',
427
+ description: 'Monday.com API version (e.g., 2025-01, 2024-10)',
428
+ displayOptions: { show: { resource: ['query'] } },
429
+ },
422
430
  {
423
431
  displayName: 'Operation',
424
432
  name: 'operation',
@@ -2128,11 +2136,11 @@ class Worktables {
2128
2136
  name: 'limit',
2129
2137
  type: 'number',
2130
2138
  typeOptions: {
2131
- minValue: 1,
2139
+ minValue: 0,
2132
2140
  },
2133
2141
  default: 50,
2134
2142
  description: 'Max number of results to return',
2135
- hint: 'If 0 is provided, all items will be returned',
2143
+ hint: 'If 0 is provided, all items will be returned. This may take longer for large boards.',
2136
2144
  displayOptions: {
2137
2145
  show: {
2138
2146
  operation: ['listBoardItems'],
@@ -2755,7 +2763,7 @@ class Worktables {
2755
2763
  };
2756
2764
  }
2757
2765
  async execute() {
2758
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24;
2766
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27;
2759
2767
  const resource = this.getNodeParameter('resource', 0);
2760
2768
  const operation = this.getNodeParameter('operation', 0);
2761
2769
  const credentials = await this.getCredentials('WorktablesApi');
@@ -4260,8 +4268,9 @@ class Worktables {
4260
4268
  }
4261
4269
  let mutation;
4262
4270
  let formatted;
4271
+ let itemUpdated = false;
4263
4272
  if (itemIdOptional && itemIdOptional.trim() !== '') {
4264
- console.log('Updating existing item:', itemIdOptional);
4273
+ console.log('Attempting to update existing item:', itemIdOptional);
4265
4274
  const escapedColumnValues = (0, worktablesHelpers_1.escapeGraphQLJSONString)(column_values_object);
4266
4275
  mutation = `mutation {
4267
4276
  change_multiple_column_values(
@@ -4285,16 +4294,24 @@ class Worktables {
4285
4294
  body: { query: mutation },
4286
4295
  });
4287
4296
  const responseData = JSON.parse(response);
4288
- const itemData = responseData.data.change_multiple_column_values;
4289
- formatted = {
4290
- id: itemData.id,
4291
- url: itemData.url,
4292
- operation: 'update',
4293
- board_id: itemData.board.id,
4294
- column_values: column_values_object,
4295
- };
4297
+ if (!responseData.errors && responseData.data && responseData.data.change_multiple_column_values) {
4298
+ const itemData = responseData.data.change_multiple_column_values;
4299
+ if (itemData && itemData.id) {
4300
+ formatted = {
4301
+ id: itemData.id,
4302
+ url: itemData.url,
4303
+ operation: 'update',
4304
+ board_id: itemData.board.id,
4305
+ column_values: column_values_object,
4306
+ };
4307
+ itemUpdated = true;
4308
+ }
4309
+ }
4310
+ if (!itemUpdated) {
4311
+ console.log('Item not found or error occurred, creating new item instead');
4312
+ }
4296
4313
  }
4297
- else {
4314
+ if (!itemUpdated) {
4298
4315
  console.log('Creating new item:', itemName);
4299
4316
  const parentId = this.getNodeParameter('parentId', 0, false);
4300
4317
  const escapedItemName = (0, worktablesHelpers_1.escapeGraphQLString)(itemName);
@@ -4415,51 +4432,150 @@ class Worktables {
4415
4432
  if (!boardId) {
4416
4433
  throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: 'Board ID is required.' });
4417
4434
  }
4418
- const query = `
4435
+ const queryColumnValues = `
4436
+ column_values {
4437
+ id
4438
+ text
4439
+ value
4440
+ type
4441
+ ... on BoardRelationValue {
4442
+ display_value
4443
+ linked_item_ids
4444
+ }
4445
+ ... on MirrorValue {
4446
+ display_value
4447
+ mirrored_items {
4448
+ linked_board_id
4449
+ }
4450
+ }
4451
+ }
4452
+ `;
4453
+ const querySubitems = `
4454
+ subitems {
4455
+ id
4456
+ name
4457
+ url
4458
+ board {
4459
+ id
4460
+ }
4461
+ created_at
4462
+ updated_at
4463
+ ${queryColumnValues}
4464
+ }
4465
+ `;
4466
+ let allItems = [];
4467
+ let cursor = null;
4468
+ const pageLimit = 100;
4469
+ do {
4470
+ const cursorParam = cursor ? `, cursor: "${cursor}"` : '';
4471
+ let currentLimit;
4472
+ if (limit === 0) {
4473
+ currentLimit = pageLimit;
4474
+ }
4475
+ else {
4476
+ const remaining = limit - allItems.length;
4477
+ currentLimit = remaining > pageLimit ? pageLimit : remaining;
4478
+ }
4479
+ const query = `
4419
4480
  query {
4420
- boards (ids: ${boardId}) {
4421
- items_page(limit: ${limit}) {
4481
+ boards (ids: [${boardId}]) {
4482
+ items_page(limit: ${currentLimit}${cursorParam}) {
4483
+ cursor
4422
4484
  items {
4423
- id
4424
- updates {
4425
- id
4426
- body
4427
- }
4428
- assets {
4429
4485
  id
4430
4486
  name
4431
- public_url
4432
4487
  url
4433
- }
4434
- column_values {
4435
- id
4436
- text
4437
- value
4488
+ board {
4489
+ id
4438
4490
  }
4439
4491
  group {
4440
- id
4441
- title
4442
- }
4443
- subitems {
4444
- id
4445
- column_values {
4446
4492
  id
4447
- text
4448
- value
4449
- }
4493
+ title
4494
+ color
4495
+ position
4450
4496
  }
4451
- url
4497
+ created_at
4498
+ updated_at
4499
+ ${queryColumnValues}
4500
+ ${querySubitems}
4452
4501
  }
4453
4502
  }
4454
4503
  }
4455
- }`;
4456
- response = await this.helpers.request({
4457
- method: 'POST',
4458
- url: 'https://api.monday.com/v2',
4459
- headers,
4460
- body: { query },
4461
- });
4462
- break;
4504
+ }
4505
+ `;
4506
+ const rawResponse = await this.helpers.request({
4507
+ method: 'POST',
4508
+ url: 'https://api.monday.com/v2',
4509
+ headers,
4510
+ body: { query },
4511
+ });
4512
+ const parsed = typeof rawResponse === 'string' ? JSON.parse(rawResponse) : rawResponse;
4513
+ const itemsPage = (_z = (_y = (_x = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _x === void 0 ? void 0 : _x.boards) === null || _y === void 0 ? void 0 : _y[0]) === null || _z === void 0 ? void 0 : _z.items_page;
4514
+ const items = (itemsPage === null || itemsPage === void 0 ? void 0 : itemsPage.items) || [];
4515
+ cursor = (itemsPage === null || itemsPage === void 0 ? void 0 : itemsPage.cursor) || null;
4516
+ allItems = allItems.concat(items);
4517
+ if (limit > 0 && allItems.length >= limit) {
4518
+ if (allItems.length > limit) {
4519
+ allItems = allItems.slice(0, limit);
4520
+ }
4521
+ break;
4522
+ }
4523
+ if (!cursor) {
4524
+ break;
4525
+ }
4526
+ } while (true);
4527
+ const formattedItems = await Promise.all(allItems.map(async (item) => {
4528
+ const columnValues = item.column_values || [];
4529
+ const formatted = {
4530
+ id: item.id,
4531
+ name: item.name,
4532
+ url: item.url,
4533
+ created_at: item.created_at,
4534
+ updated_at: item.updated_at,
4535
+ board: item.board ? {
4536
+ id: item.board.id,
4537
+ } : undefined,
4538
+ group: item.group ? {
4539
+ id: item.group.id,
4540
+ title: item.group.title,
4541
+ color: item.group.color,
4542
+ position: item.group.position,
4543
+ } : undefined,
4544
+ column_values: {},
4545
+ };
4546
+ for (const col of columnValues) {
4547
+ if (col.type === 'subtasks')
4548
+ continue;
4549
+ const formattedCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
4550
+ if (formattedCol) {
4551
+ formatted.column_values[col.id] = formattedCol;
4552
+ }
4553
+ }
4554
+ if (item.subitems && Array.isArray(item.subitems)) {
4555
+ formatted.subitems = await Promise.all(item.subitems.map(async (subitem) => {
4556
+ const subFormatted = {
4557
+ id: subitem.id,
4558
+ name: subitem.name,
4559
+ url: subitem.url,
4560
+ created_at: subitem.created_at,
4561
+ updated_at: subitem.updated_at,
4562
+ board: subitem.board ? {
4563
+ id: subitem.board.id,
4564
+ } : undefined,
4565
+ column_values: {},
4566
+ };
4567
+ for (const col of subitem.column_values || []) {
4568
+ const subCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
4569
+ if (subCol) {
4570
+ subFormatted.column_values[col.id] = subCol;
4571
+ }
4572
+ }
4573
+ return subFormatted;
4574
+ }));
4575
+ }
4576
+ return formatted;
4577
+ }));
4578
+ return [formattedItems.map((item) => ({ json: item }))];
4463
4579
  }
4464
4580
  case 'searchItems': {
4465
4581
  const boardId = this.getNodeParameter('boardId', 0);
@@ -4468,7 +4584,7 @@ class Worktables {
4468
4584
  const sortOptions = this.getNodeParameter('sortOptions', 0, { sortBy: [] });
4469
4585
  const logicalOperator = this.getNodeParameter('logicalOperator', 0);
4470
4586
  let rulesArray = [];
4471
- if (((_x = filterRules === null || filterRules === void 0 ? void 0 : filterRules.rule) === null || _x === void 0 ? void 0 : _x.length) > 0) {
4587
+ if (((_0 = filterRules === null || filterRules === void 0 ? void 0 : filterRules.rule) === null || _0 === void 0 ? void 0 : _0.length) > 0) {
4472
4588
  rulesArray = filterRules.rule.map((rule) => {
4473
4589
  let formattedValue;
4474
4590
  if (['is_empty', 'is_not_empty'].includes(rule.operator)) {
@@ -4512,7 +4628,7 @@ class Worktables {
4512
4628
  });
4513
4629
  }
4514
4630
  const orderByArray = [];
4515
- if (((_y = sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.sortBy) === null || _y === void 0 ? void 0 : _y.length) > 0) {
4631
+ if (((_1 = sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.sortBy) === null || _1 === void 0 ? void 0 : _1.length) > 0) {
4516
4632
  sortOptions.sortBy.forEach((sort) => {
4517
4633
  orderByArray.push(`{
4518
4634
  column_id: "${sort.columnId}",
@@ -4558,7 +4674,7 @@ class Worktables {
4558
4674
  body: { query },
4559
4675
  });
4560
4676
  const parsed = JSON.parse(rawResponse);
4561
- const items = ((_2 = (_1 = (_0 = (_z = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _z === void 0 ? void 0 : _z.boards) === null || _0 === void 0 ? void 0 : _0[0]) === null || _1 === void 0 ? void 0 : _1.items_page) === null || _2 === void 0 ? void 0 : _2.items) || [];
4677
+ const items = ((_5 = (_4 = (_3 = (_2 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _2 === void 0 ? void 0 : _2.boards) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.items_page) === null || _5 === void 0 ? void 0 : _5.items) || [];
4562
4678
  const formattedItems = await Promise.all(items.map(async (item) => {
4563
4679
  const formatted = {
4564
4680
  id: item.id,
@@ -4592,7 +4708,7 @@ class Worktables {
4592
4708
  const advancedSortOptions = this.getNodeParameter('advancedSortOptions', 0, { sortBy: [] });
4593
4709
  const logicalOperator = this.getNodeParameter('logicalOperatorAdvanced', 0);
4594
4710
  let rulesArray = [];
4595
- if (((_3 = advancedFilterRules === null || advancedFilterRules === void 0 ? void 0 : advancedFilterRules.rule) === null || _3 === void 0 ? void 0 : _3.length) > 0) {
4711
+ if (((_6 = advancedFilterRules === null || advancedFilterRules === void 0 ? void 0 : advancedFilterRules.rule) === null || _6 === void 0 ? void 0 : _6.length) > 0) {
4596
4712
  console.log('Processing filter rules:', advancedFilterRules.rule);
4597
4713
  rulesArray = advancedFilterRules.rule.map((rule) => {
4598
4714
  let formattedValue;
@@ -4808,7 +4924,7 @@ class Worktables {
4808
4924
  });
4809
4925
  }
4810
4926
  const orderByArray = [];
4811
- if (((_4 = advancedSortOptions === null || advancedSortOptions === void 0 ? void 0 : advancedSortOptions.sortBy) === null || _4 === void 0 ? void 0 : _4.length) > 0) {
4927
+ if (((_7 = advancedSortOptions === null || advancedSortOptions === void 0 ? void 0 : advancedSortOptions.sortBy) === null || _7 === void 0 ? void 0 : _7.length) > 0) {
4812
4928
  advancedSortOptions.sortBy.forEach((sort) => {
4813
4929
  orderByArray.push(`{
4814
4930
  column_id: "${sort.columnId}",
@@ -4880,7 +4996,7 @@ class Worktables {
4880
4996
  body: { query: testQuery },
4881
4997
  });
4882
4998
  const testParsed = JSON.parse(testResponse);
4883
- const testItems = ((_8 = (_7 = (_6 = (_5 = testParsed === null || testParsed === void 0 ? void 0 : testParsed.data) === null || _5 === void 0 ? void 0 : _5.boards) === null || _6 === void 0 ? void 0 : _6[0]) === null || _7 === void 0 ? void 0 : _7.items_page) === null || _8 === void 0 ? void 0 : _8.items) || [];
4999
+ const testItems = ((_11 = (_10 = (_9 = (_8 = testParsed === null || testParsed === void 0 ? void 0 : testParsed.data) === null || _8 === void 0 ? void 0 : _8.boards) === null || _9 === void 0 ? void 0 : _9[0]) === null || _10 === void 0 ? void 0 : _10.items_page) === null || _11 === void 0 ? void 0 : _11.items) || [];
4884
5000
  console.log('Test - Items in board (no filters):', testItems.length);
4885
5001
  if (testItems.length > 0) {
4886
5002
  console.log('Sample item column values:', testItems[0].column_values);
@@ -4892,7 +5008,7 @@ class Worktables {
4892
5008
  body: { query },
4893
5009
  });
4894
5010
  const parsed = JSON.parse(rawResponse);
4895
- const itemsPage = (_11 = (_10 = (_9 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _9 === void 0 ? void 0 : _9.boards) === null || _10 === void 0 ? void 0 : _10[0]) === null || _11 === void 0 ? void 0 : _11.items_page;
5011
+ const itemsPage = (_14 = (_13 = (_12 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _12 === void 0 ? void 0 : _12.boards) === null || _13 === void 0 ? void 0 : _13[0]) === null || _14 === void 0 ? void 0 : _14.items_page;
4896
5012
  const items = (itemsPage === null || itemsPage === void 0 ? void 0 : itemsPage.items) || [];
4897
5013
  const nextCursor = itemsPage === null || itemsPage === void 0 ? void 0 : itemsPage.cursor;
4898
5014
  const hasMore = nextCursor ? true : false;
@@ -5003,6 +5119,16 @@ class Worktables {
5003
5119
  items {
5004
5120
  id
5005
5121
  name
5122
+ url
5123
+ board {
5124
+ id
5125
+ }
5126
+ group {
5127
+ id
5128
+ title
5129
+ color
5130
+ position
5131
+ }
5006
5132
  column_values {
5007
5133
  id
5008
5134
  text
@@ -5019,11 +5145,6 @@ class Worktables {
5019
5145
  }
5020
5146
  }
5021
5147
  }
5022
- group {
5023
- id
5024
- title
5025
- }
5026
- state
5027
5148
  created_at
5028
5149
  updated_at
5029
5150
  }
@@ -5039,18 +5160,29 @@ class Worktables {
5039
5160
  body: { query },
5040
5161
  });
5041
5162
  const parsed = JSON.parse(rawResponse);
5042
- const items = ((_17 = (_16 = (_15 = (_14 = (_13 = (_12 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _12 === void 0 ? void 0 : _12.boards) === null || _13 === void 0 ? void 0 : _13[0]) === null || _14 === void 0 ? void 0 : _14.groups) === null || _15 === void 0 ? void 0 : _15[0]) === null || _16 === void 0 ? void 0 : _16.items_page) === null || _17 === void 0 ? void 0 : _17.items) || [];
5163
+ const items = ((_20 = (_19 = (_18 = (_17 = (_16 = (_15 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _15 === void 0 ? void 0 : _15.boards) === null || _16 === void 0 ? void 0 : _16[0]) === null || _17 === void 0 ? void 0 : _17.groups) === null || _18 === void 0 ? void 0 : _18[0]) === null || _19 === void 0 ? void 0 : _19.items_page) === null || _20 === void 0 ? void 0 : _20.items) || [];
5043
5164
  const formattedItems = await Promise.all(items.map(async (item) => {
5165
+ const columnValues = item.column_values || [];
5044
5166
  const formatted = {
5045
5167
  id: item.id,
5046
5168
  name: item.name,
5047
- group: item.group,
5048
- state: item.state,
5169
+ url: item.url,
5049
5170
  created_at: item.created_at,
5050
5171
  updated_at: item.updated_at,
5172
+ board: item.board ? {
5173
+ id: item.board.id,
5174
+ } : undefined,
5175
+ group: item.group ? {
5176
+ id: item.group.id,
5177
+ title: item.group.title,
5178
+ color: item.group.color,
5179
+ position: item.group.position,
5180
+ } : undefined,
5051
5181
  column_values: {},
5052
5182
  };
5053
- for (const col of item.column_values || []) {
5183
+ for (const col of columnValues) {
5184
+ if (col.type === 'subtasks')
5185
+ continue;
5054
5186
  const formattedCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
5055
5187
  if (formattedCol) {
5056
5188
  formatted.column_values[col.id] = formattedCol;
@@ -5112,7 +5244,7 @@ class Worktables {
5112
5244
  response = await (0, isErrorResponse_1.parseApiResponse)(response);
5113
5245
  if (response.success) {
5114
5246
  const parsed = JSON.parse(response.data);
5115
- const updates = ((_20 = (_19 = (_18 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _18 === void 0 ? void 0 : _18.items) === null || _19 === void 0 ? void 0 : _19[0]) === null || _20 === void 0 ? void 0 : _20.updates) || [];
5247
+ const updates = ((_23 = (_22 = (_21 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _21 === void 0 ? void 0 : _21.items) === null || _22 === void 0 ? void 0 : _22[0]) === null || _23 === void 0 ? void 0 : _23.updates) || [];
5116
5248
  return [updates.map((update) => ({ json: update }))];
5117
5249
  }
5118
5250
  else {
@@ -5169,7 +5301,7 @@ class Worktables {
5169
5301
  console.log('variables:', variables);
5170
5302
  response = await (0, worktablesHelpers_1.makeGraphQLRequest)(this, mutation, headers, variables);
5171
5303
  console.log('Create Update Result:', JSON.stringify(response, null, 2));
5172
- const updateId = (_22 = (_21 = JSON.parse(response).data) === null || _21 === void 0 ? void 0 : _21.create_update) === null || _22 === void 0 ? void 0 : _22.id;
5304
+ const updateId = (_25 = (_24 = JSON.parse(response).data) === null || _24 === void 0 ? void 0 : _24.create_update) === null || _25 === void 0 ? void 0 : _25.id;
5173
5305
  if (!updateId) {
5174
5306
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
5175
5307
  message: 'Error creating update: Update not created, no ID returned',
@@ -5475,7 +5607,7 @@ class Worktables {
5475
5607
  body: { query },
5476
5608
  json: true,
5477
5609
  });
5478
- const asset = (_24 = (_23 = responseFile === null || responseFile === void 0 ? void 0 : responseFile.data) === null || _23 === void 0 ? void 0 : _23.assets) === null || _24 === void 0 ? void 0 : _24[0];
5610
+ const asset = (_27 = (_26 = responseFile === null || responseFile === void 0 ? void 0 : responseFile.data) === null || _26 === void 0 ? void 0 : _26.assets) === null || _27 === void 0 ? void 0 : _27[0];
5479
5611
  if (!(asset === null || asset === void 0 ? void 0 : asset.public_url)) {
5480
5612
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
5481
5613
  message: 'Public URL not found for the given file ID.',
@@ -5503,16 +5635,22 @@ class Worktables {
5503
5635
  }
5504
5636
  case 'query': {
5505
5637
  const runQuery = this.getNodeParameter('runQuery', 0);
5638
+ const apiVersion = this.getNodeParameter('apiVersion', 0);
5506
5639
  if (!runQuery) {
5507
5640
  throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: 'Invalid item data.' });
5508
5641
  }
5509
5642
  switch (operation) {
5510
5643
  case 'query': {
5511
5644
  console.log('Run Query:', runQuery);
5645
+ const apiUrl = `https://api.monday.com/v2`;
5646
+ const queryHeaders = {
5647
+ ...headers,
5648
+ 'API-Version': apiVersion,
5649
+ };
5512
5650
  response = await this.helpers.request({
5513
5651
  method: 'POST',
5514
- url: 'https://api.monday.com/v2',
5515
- headers,
5652
+ url: apiUrl,
5653
+ headers: queryHeaders,
5516
5654
  body: { query: runQuery },
5517
5655
  });
5518
5656
  break;