Skip to content

Commit

Permalink
fix(Monday.com Node): Migrate to api 2023-10 (#8254)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Jan 10, 2024
1 parent f208a6e commit ccde38a
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 111 deletions.
17 changes: 17 additions & 0 deletions packages/cli/BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,29 @@ The flag `N8N_CACHE_ENABLED` was removed. The cache is now always enabled.

Additionally, expressions in credentials now follow the paired item, so if you have multiple input items, n8n will try to pair the matching row to fill in the credential details.

In the Monday.com Node, due to API changes, the data structure of entries in `column_values` array has changed

### When is action necessary?

If you are using the flag `N8N_CACHE_ENABLED`, remove it from your settings.

In regards to credentials, if you use expression in credentials, you might want to revisit them. Previously, n8n would stick to the first item only, but now it will try to match the proper paired item.

If you are using the Monday.com node and refering to `column_values` property, check in table below if you are using any of the affected properties of its entries.

| Resource | Operation | Previous | New |
| ---------- | ------------------- | --------------- | ------------------- |
| Board | Get | owner | owners |
| Board | Get All | owner | owners |
| Board Item | Get | title | column.title |
| Board Item | Get All | title | column.title |
| Board Item | Get By Column Value | title | column.title |
| Board Item | Get | additional_info | column.settings_str |
| Board Item | Get All | additional_info | column.settings_str |
| Board Item | Get By Column Value | additional_info | column.settings_str |

\*column.settings_str is not a complete equivalent additional_info

## 1.22.0

### What changed?
Expand Down
30 changes: 29 additions & 1 deletion packages/nodes-base/credentials/MondayComApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ICredentialType, INodeProperties } from 'n8n-workflow';
import type {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';

export class MondayComApi implements ICredentialType {
name = 'mondayComApi';
Expand All @@ -16,4 +21,27 @@ export class MondayComApi implements ICredentialType {
default: '',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.apiToken}}',
},
},
};

test: ICredentialTestRequest = {
request: {
headers: {
'API-Version': '2023-10',
'Content-Type': 'application/json',
},
baseURL: 'https://api.monday.com/v2',
method: 'POST',
body: JSON.stringify({
query: 'query { me { name }}',
}),
},
};
}
58 changes: 46 additions & 12 deletions packages/nodes-base/nodes/MondayCom/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,31 @@ import get from 'lodash/get';

export async function mondayComApiRequest(
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,

body: any = {},
option: IDataObject = {},
): Promise<any> {
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;

const endpoint = 'https://api.monday.com/v2/';

let options: OptionsWithUri = {
headers: {
'API-Version': '2023-10',
'Content-Type': 'application/json',
},
method: 'POST',
body,
uri: endpoint,
uri: 'https://api.monday.com/v2/',
json: true,
};

options = Object.assign({}, options, option);
try {
if (authenticationMethod === 'accessToken') {
const credentials = await this.getCredentials('mondayComApi');

options.headers = { Authorization: `Bearer ${credentials.apiToken}` };
try {
let credentialType = 'mondayComApi';

return await this.helpers.request(options);
} else {
return await this.helpers.requestOAuth2.call(this, 'mondayComOAuth2Api', options);
if (authenticationMethod === 'oAuth2') {
credentialType = 'mondayComOAuth2Api';
}
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
Expand All @@ -50,7 +47,6 @@ export async function mondayComApiRequest(
export async function mondayComApiRequestAllItems(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,

body: any = {},
): Promise<any> {
const returnData: IDataObject[] = [];
Expand All @@ -66,3 +62,41 @@ export async function mondayComApiRequestAllItems(
} while (get(responseData, propertyName).length > 0);
return returnData;
}

export async function mondayComApiPaginatedRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
itemsPath: string,
fieldsToReturn: string,
body: IDataObject = {},
) {
const returnData: IDataObject[] = [];

const initialResponse = await mondayComApiRequest.call(this, body);
const data = get(initialResponse, itemsPath) as IDataObject;

if (data) {
returnData.push.apply(returnData, data.items as IDataObject[]);

let cursor: null | string = data.cursor as string;

while (cursor) {
const responseData = (
(await mondayComApiRequest.call(this, {
query: `query ( $cursor: String!) { next_items_page (cursor: $cursor, limit: 100) { cursor items ${fieldsToReturn} } }`,
variables: {
cursor,
},
})) as IDataObject
).data as { next_items_page: { cursor: string; items: IDataObject[] } };

if (responseData && responseData.next_items_page) {
returnData.push.apply(returnData, responseData.next_items_page.items);
cursor = responseData.next_items_page.cursor;
} else {
cursor = null;
}
}
}

return returnData;
}
Loading

0 comments on commit ccde38a

Please sign in to comment.