2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-02-27 19:39:43 -08:00
|
|
|
IDataObject,
|
2023-03-06 08:33:32 -08:00
|
|
|
IExecuteFunctions,
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
ILoadOptionsFunctions,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeExecutionData,
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
INodePropertyOptions,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
import { linkedInApiRequest } from './GenericFunctions';
|
2022-08-17 08:50:24 -07:00
|
|
|
import { postFields, postOperations } from './PostDescription';
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
|
|
|
export class LinkedIn implements INodeType {
|
2022-04-22 09:29:51 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-missing-subtitle
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'LinkedIn',
|
|
|
|
name: 'linkedIn',
|
2022-06-23 14:15:29 -07:00
|
|
|
icon: 'file:linkedin.svg',
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
group: ['input'],
|
|
|
|
version: 1,
|
2022-06-23 14:15:29 -07:00
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Consume LinkedIn API',
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
defaults: {
|
|
|
|
name: 'LinkedIn',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'linkedInOAuth2Api',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Post',
|
|
|
|
value: 'post',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'post',
|
|
|
|
},
|
|
|
|
//POST
|
|
|
|
...postOperations,
|
|
|
|
...postFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
// Get Person URN which has to be used with other LinkedIn API Requests
|
|
|
|
// https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin
|
|
|
|
async getPersonUrn(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const person = await linkedInApiRequest.call(this, 'GET', '/me', {});
|
2022-08-17 08:50:24 -07:00
|
|
|
returnData.push({
|
|
|
|
name: `${person.localizedFirstName} ${person.localizedLastName}`,
|
|
|
|
value: person.id,
|
|
|
|
});
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
return returnData;
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2023-01-31 11:39:20 -08:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2022-06-23 14:15:29 -07:00
|
|
|
|
2022-12-02 06:25:21 -08:00
|
|
|
let body: any = {};
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
if (resource === 'post') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
const text = this.getNodeParameter('text', i) as string;
|
|
|
|
const shareMediaCategory = this.getNodeParameter('shareMediaCategory', i) as string;
|
|
|
|
const postAs = this.getNodeParameter('postAs', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let authorUrn = '';
|
|
|
|
let visibility = 'PUBLIC';
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (postAs === 'person') {
|
|
|
|
const personUrn = this.getNodeParameter('person', i) as string;
|
|
|
|
// Only if posting as a person can user decide if post visible by public or connections
|
2022-08-17 08:50:24 -07:00
|
|
|
visibility = (additionalFields.visibility as string) || 'PUBLIC';
|
2021-07-19 23:58:54 -07:00
|
|
|
authorUrn = `urn:li:person:${personUrn}`;
|
|
|
|
} else {
|
|
|
|
const organizationUrn = this.getNodeParameter('organization', i) as string;
|
|
|
|
authorUrn = `urn:li:organization:${organizationUrn}`;
|
|
|
|
}
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let description = '';
|
|
|
|
let title = '';
|
|
|
|
let originalUrl = '';
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2023-03-31 06:04:43 -07:00
|
|
|
body = {
|
|
|
|
author: authorUrn,
|
|
|
|
lifecycleState: 'PUBLISHED',
|
|
|
|
distribution: {
|
|
|
|
feedDistribution: 'MAIN_FEED',
|
|
|
|
thirdPartyDistributionChannels: [],
|
|
|
|
},
|
|
|
|
visibility,
|
|
|
|
};
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (shareMediaCategory === 'IMAGE') {
|
|
|
|
if (additionalFields.title) {
|
|
|
|
title = additionalFields.title as string;
|
|
|
|
}
|
|
|
|
// Send a REQUEST to prepare a register of a media image file
|
|
|
|
const registerRequest = {
|
2023-03-31 06:04:43 -07:00
|
|
|
initializeUploadRequest: {
|
2021-07-19 23:58:54 -07:00
|
|
|
owner: authorUrn,
|
|
|
|
},
|
|
|
|
};
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const registerObject = await linkedInApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2023-03-31 06:04:43 -07:00
|
|
|
'/images?action=initializeUpload',
|
2022-08-17 08:50:24 -07:00
|
|
|
registerRequest,
|
|
|
|
);
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2023-03-06 08:33:32 -08:00
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
|
|
|
this.helpers.assertBinaryData(i, binaryPropertyName);
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2023-03-06 08:33:32 -08:00
|
|
|
const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
2023-03-31 06:04:43 -07:00
|
|
|
const { uploadUrl, image } = registerObject.value;
|
|
|
|
await linkedInApiRequest.call(this, 'POST', uploadUrl as string, buffer, true);
|
|
|
|
|
|
|
|
const imageBody = {
|
|
|
|
content: {
|
|
|
|
media: {
|
|
|
|
title,
|
|
|
|
id: image,
|
2021-07-19 23:58:54 -07:00
|
|
|
},
|
|
|
|
},
|
2023-03-31 06:04:43 -07:00
|
|
|
commentary: text,
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
2023-03-31 06:04:43 -07:00
|
|
|
Object.assign(body, imageBody);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (shareMediaCategory === 'ARTICLE') {
|
|
|
|
if (additionalFields.description) {
|
|
|
|
description = additionalFields.description as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.title) {
|
|
|
|
title = additionalFields.title as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.originalUrl) {
|
|
|
|
originalUrl = additionalFields.originalUrl as string;
|
|
|
|
}
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
|
2023-03-31 06:04:43 -07:00
|
|
|
const articleBody = {
|
|
|
|
content: {
|
|
|
|
article: {
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
source: originalUrl,
|
2021-07-19 23:58:54 -07:00
|
|
|
},
|
|
|
|
},
|
2023-03-31 06:04:43 -07:00
|
|
|
commentary: text,
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
2023-03-31 06:04:43 -07:00
|
|
|
Object.assign(body, articleBody);
|
2022-06-23 14:15:29 -07:00
|
|
|
if (description === '') {
|
2023-03-31 06:04:43 -07:00
|
|
|
delete body.description;
|
2022-06-23 14:15:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (title === '') {
|
2023-03-31 06:04:43 -07:00
|
|
|
delete body.title;
|
2022-06-23 14:15:29 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2023-03-31 06:04:43 -07:00
|
|
|
Object.assign(body, { commentary: text });
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2023-03-31 06:04:43 -07:00
|
|
|
const endpoint = '/posts';
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await linkedInApiRequest.call(this, 'POST', endpoint, body);
|
|
|
|
}
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
}
|
2023-01-31 11:39:20 -08:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2023-01-31 11:39:20 -08:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2023-01-31 11:39:20 -08:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-31 11:39:20 -08:00
|
|
|
return this.prepareOutputData(returnData);
|
:sparkles: Add LinkedIn Integration (#942)
* :construction: node logic, request logic, authentication, logo, descriptions
* :construction: Posting image, article and text finished.
* :construction: Posting image, article and text in post finished
* :zap: Post creation (image, articles, text)
* :zap: Added post creation by organization, fixed up descriptions, credentials, indentation
* :zap: Fix issues on LinkedIn-Node
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
2020-09-17 14:32:12 -07:00
|
|
|
}
|
|
|
|
}
|