mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add LinkedIn Integration (#942)
* 🚧 node logic, request logic, authentication, logo, descriptions * 🚧 Posting image, article and text finished. * 🚧 Posting image, article and text in post finished * ⚡ Post creation (image, articles, text) * ⚡ Added post creation by organization, fixed up descriptions, credentials, indentation * ⚡ Fix issues on LinkedIn-Node Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: Jan <janober@users.noreply.github.com>
This commit is contained in:
52
packages/nodes-base/nodes/LinkedIn/GenericFunctions.ts
Normal file
52
packages/nodes-base/nodes/LinkedIn/GenericFunctions.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
OptionsWithUrl,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
export async function linkedInApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, binary?: boolean, headers?: object): Promise<any> { // tslint:disable-line:no-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) {
|
||||
if (error.respose && error.response.body && error.response.body.detail) {
|
||||
throw new Error(`Linkedin Error response [${error.statusCode}]: ${error.response.body.detail}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
} catch (exception) {
|
||||
result = '';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user