mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
91d7e16c81
* 🔨 formatting nodes with prettier
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import { OptionsWithUrl } from 'request';
|
|
|
|
import { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
|
import { NodeApiError } from 'n8n-workflow';
|
|
|
|
export async function linkedInApiRequest(
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
method: string,
|
|
endpoint: string,
|
|
// tslint:disable-next-line:no-any
|
|
body: any = {},
|
|
binary?: boolean,
|
|
headers?: object,
|
|
// tslint:disable-next-line:no-any
|
|
): Promise<any> {
|
|
const options: OptionsWithUrl = {
|
|
headers: {
|
|
Accept: 'application/json',
|
|
'X-Restli-Protocol-Version': '2.0.0',
|
|
},
|
|
method,
|
|
body,
|
|
url: binary ? endpoint : `https://api.linkedin.com/v2${endpoint}`,
|
|
json: true,
|
|
};
|
|
|
|
// If uploading binary data
|
|
if (binary) {
|
|
delete options.json;
|
|
options.encoding = null;
|
|
}
|
|
|
|
if (Object.keys(body).length === 0) {
|
|
delete options.body;
|
|
}
|
|
|
|
try {
|
|
return await this.helpers.requestOAuth2!.call(this, 'linkedInOAuth2Api', options, {
|
|
tokenType: 'Bearer',
|
|
});
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error);
|
|
}
|
|
}
|
|
|
|
// tslint:disable-next-line:no-any
|
|
export function validateJSON(json: string | undefined): any {
|
|
let result;
|
|
try {
|
|
result = JSON.parse(json!);
|
|
} catch (exception) {
|
|
result = '';
|
|
}
|
|
return result;
|
|
}
|