mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 21:19:43 -08:00
1111c915f2
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import type { OptionsWithUri } from 'request';
|
|
|
|
import type {
|
|
IExecuteFunctions,
|
|
ILoadOptionsFunctions,
|
|
IDataObject,
|
|
IHookFunctions,
|
|
IWebhookFunctions,
|
|
JsonObject,
|
|
} from 'n8n-workflow';
|
|
import { NodeApiError } from 'n8n-workflow';
|
|
|
|
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: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
method: 'POST',
|
|
body,
|
|
uri: endpoint,
|
|
json: true,
|
|
};
|
|
options = Object.assign({}, options, option);
|
|
try {
|
|
if (authenticationMethod === 'accessToken') {
|
|
const credentials = await this.getCredentials('mondayComApi');
|
|
|
|
options.headers = { Authorization: `Bearer ${credentials.apiToken}` };
|
|
|
|
return await this.helpers.request(options);
|
|
} else {
|
|
return await this.helpers.requestOAuth2.call(this, 'mondayComOAuth2Api', options);
|
|
}
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
|
}
|
|
}
|
|
|
|
export async function mondayComApiRequestAllItems(
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
propertyName: string,
|
|
|
|
body: any = {},
|
|
): Promise<any> {
|
|
const returnData: IDataObject[] = [];
|
|
|
|
let responseData;
|
|
body.variables.limit = 50;
|
|
body.variables.page = 1;
|
|
|
|
do {
|
|
responseData = await mondayComApiRequest.call(this, body);
|
|
returnData.push.apply(returnData, get(responseData, propertyName) as IDataObject[]);
|
|
body.variables.page++;
|
|
} while (get(responseData, propertyName).length > 0);
|
|
return returnData;
|
|
}
|