Skip to content

Commit 4c21eb2

Browse files
Create Post
1 parent 271ba09 commit 4c21eb2

7 files changed

Lines changed: 152 additions & 3 deletions

File tree

nodes/LinkedApi/LinkedApi.node.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
CustomWorkflow,
2323
CheckConnectionStatus,
2424
CommentOnPost,
25+
CreatePost,
2526
FetchCompany,
2627
FetchPerson,
2728
FetchPost,
@@ -46,6 +47,7 @@ import { LinkedApiOperation } from './shared/LinkedApiOperation';
4647
const operations: Record<string, LinkedApiOperation> = {
4748
checkConnectionStatus: new CheckConnectionStatus(),
4849
commentOnPost: new CommentOnPost(),
50+
createPost: new CreatePost(),
4951
fetchPerson: new FetchPerson(),
5052
fetchCompany: new FetchCompany(),
5153
fetchPost: new FetchPost(),
@@ -107,6 +109,7 @@ export class LinkedApi implements INodeType {
107109
// Standard actions
108110
...operations.checkConnectionStatus.operationFields,
109111
...operations.commentOnPost.operationFields,
112+
...operations.createPost.operationFields,
110113
...operations.fetchPerson.operationFields,
111114
...operations.fetchCompany.operationFields,
112115
...operations.fetchPost.operationFields,
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import type { IExecuteFunctions, INodeProperties } from 'n8n-workflow';
2+
import {
3+
createParameterWithDisplayOptions,
4+
postTextParameter,
5+
postCompanyUrlParameter,
6+
} from '../../shared/SharedParameters';
7+
import { StandardLinkedApiOperation } from '../../shared/LinkedApiOperation';
8+
import { AVAILABLE_ACTION } from '../../shared/AvailableActions';
9+
10+
export class CreatePost extends StandardLinkedApiOperation {
11+
operationName = AVAILABLE_ACTION.createPost;
12+
13+
fields: INodeProperties[] = [
14+
createParameterWithDisplayOptions(postTextParameter, this.show),
15+
createParameterWithDisplayOptions(postCompanyUrlParameter, this.show),
16+
{
17+
displayName: 'Attachments',
18+
name: 'attachments',
19+
type: 'fixedCollection',
20+
typeOptions: {
21+
multipleValues: true,
22+
maxValue: 9,
23+
},
24+
default: {},
25+
displayOptions: { show: this.show },
26+
description: 'Media attachments for the post (max 9 images, or 1 video, or 1 document)',
27+
placeholder: 'Add Attachment',
28+
options: [
29+
{
30+
name: 'attachment',
31+
displayName: 'Attachment',
32+
values: [
33+
{
34+
displayName: 'Type',
35+
name: 'type',
36+
type: 'options',
37+
default: 'image',
38+
description: 'Type of media attachment',
39+
// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items
40+
options: [
41+
{
42+
name: 'Image',
43+
value: 'image',
44+
description: 'Image file (JPEG, PNG, GIF, WebP; max 8MB)',
45+
},
46+
{
47+
name: 'Video',
48+
value: 'video',
49+
description: 'Video file (MP4, MOV, WebM; max 200MB)',
50+
},
51+
{
52+
name: 'Document',
53+
value: 'document',
54+
description: 'PDF document (max 100MB)',
55+
},
56+
],
57+
},
58+
{
59+
displayName: 'URL',
60+
name: 'url',
61+
type: 'string',
62+
default: '',
63+
placeholder: 'https://example.com/file.jpg',
64+
description: 'Publicly accessible URL of the media file',
65+
},
66+
{
67+
displayName: 'Document Name',
68+
name: 'name',
69+
type: 'string',
70+
default: '',
71+
placeholder: 'My Document',
72+
description: 'Display name for the document (required for documents)',
73+
displayOptions: {
74+
show: {
75+
type: ['document'],
76+
},
77+
},
78+
},
79+
],
80+
},
81+
],
82+
},
83+
];
84+
85+
public body(context: IExecuteFunctions): Record<string, any> {
86+
const text = this.stringParameter(context, 'postText');
87+
const companyUrl = this.stringParameter(context, 'postCompanyUrl');
88+
const attachmentsData = context.getNodeParameter('attachments', 0, {}) as {
89+
attachment?: Array<{ type: string; url: string; name?: string }>;
90+
};
91+
92+
const body: Record<string, any> = { text };
93+
94+
if (companyUrl) {
95+
body.companyUrl = companyUrl;
96+
}
97+
98+
if (attachmentsData.attachment && attachmentsData.attachment.length > 0) {
99+
body.attachments = attachmentsData.attachment.map((item) => {
100+
const attachment: Record<string, string> = {
101+
url: item.url,
102+
type: item.type,
103+
};
104+
105+
if (item.type === 'document' && item.name) {
106+
attachment.name = item.name;
107+
}
108+
109+
return attachment;
110+
});
111+
}
112+
113+
return body;
114+
}
115+
}

nodes/LinkedApi/operations/webhook/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './CheckConnectionStatus';
22
export * from './CommentOnPost';
3+
export * from './CreatePost';
34
export * from './CustomWorkflow';
45
export * from './FetchCompany';
56
export * from './FetchPerson';

nodes/LinkedApi/shared/AvailableActions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { INodeProperties, INodePropertyOptions } from 'n8n-workflow';
55
export const AVAILABLE_ACTION = {
66
checkConnectionStatus: 'checkConnectionStatus',
77
commentOnPost: 'commentOnPost',
8+
createPost: 'createPost',
89
fetchCompany: 'fetchCompany',
910
fetchPerson: 'fetchPerson',
1011
fetchPost: 'fetchPost',
@@ -58,6 +59,12 @@ export const availableStandardOperations: INodeProperties = {
5859
description: 'Leave a comment on a LinkedIn post',
5960
action: 'Comment on post',
6061
},
62+
{
63+
name: 'Create Post',
64+
value: AVAILABLE_ACTION.createPost,
65+
description: 'Create a new LinkedIn post',
66+
action: 'Create post',
67+
},
6168
{
6269
name: 'Fetch Company',
6370
value: AVAILABLE_ACTION.fetchCompany,

nodes/LinkedApi/shared/SharedParameters.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,29 @@ export const reactionTypeParameter: INodeProperties = {
426426
],
427427
};
428428

429+
// Create Post Parameters
430+
export const postTextParameter: INodeProperties = {
431+
displayName: 'Post Text',
432+
name: 'postText',
433+
type: 'string',
434+
typeOptions: {
435+
rows: 4,
436+
},
437+
required: true,
438+
default: '',
439+
placeholder: 'Share your thoughts...',
440+
description: 'Post content, must be up to 3000 characters',
441+
};
442+
443+
export const postCompanyUrlParameter: INodeProperties = {
444+
displayName: 'Company URL',
445+
name: 'postCompanyUrl',
446+
type: 'string',
447+
default: '',
448+
placeholder: 'https://www.linkedin.com/company/acme-corp',
449+
description: 'LinkedIn company page URL. If specified, the post will be created on the company page.',
450+
};
451+
429452
// Custom Workflow Parameters
430453
export const workflowDefinitionParameter: INodeProperties = {
431454
displayName: 'Workflow Definition',

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "n8n-nodes-linked-api",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Connect your LinkedIn accounts to n8n's automation platform.",
55
"keywords": [
66
"n8n-community-node-package",

0 commit comments

Comments
 (0)