Skip to content

Commit 11c75b1

Browse files
CreatePost operation
1 parent f66966a commit 11c75b1

File tree

8 files changed

+167
-3
lines changed

8 files changed

+167
-3
lines changed

examples/post-actions.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ async function postActionsExample(): Promise<void> {
88

99
try {
1010
console.log('🚀 Linked API Post Actions example starting...');
11+
await createPost(linkedapi);
12+
await createPostWithAttachments(linkedapi);
13+
await createCompanyPost(linkedapi);
1114
await reactToPost(linkedapi);
1215
await commentOnPost(linkedapi);
1316
} catch (error) {
@@ -20,6 +23,69 @@ async function postActionsExample(): Promise<void> {
2023
}
2124
}
2225

26+
async function createPost(linkedapi: LinkedApi): Promise<void> {
27+
console.log('\n📝 Creating a simple text post...');
28+
29+
const workflowId = await linkedapi.createPost.execute({
30+
text: 'Excited to share our latest product updates!\n\n#innovation #technology',
31+
});
32+
console.log('📝 Create post workflow started:', workflowId);
33+
34+
const result = await linkedapi.createPost.result(workflowId);
35+
if (result.errors.length > 0) {
36+
console.error('🚨 Errors:', JSON.stringify(result.errors, null, 2));
37+
} else {
38+
console.log('✅ Post created successfully');
39+
console.log('🔗 Post URL:', result.data?.postUrl);
40+
}
41+
}
42+
43+
async function createPostWithAttachments(linkedapi: LinkedApi): Promise<void> {
44+
console.log('\n🖼️ Creating a post with image attachments...');
45+
46+
const workflowId = await linkedapi.createPost.execute({
47+
text: 'Check out these amazing photos from our team event!',
48+
attachments: [
49+
{ url: 'https://example.com/photo1.jpg', type: 'image' },
50+
{ url: 'https://example.com/photo2.jpg', type: 'image' },
51+
],
52+
});
53+
console.log('🖼️ Create post with images workflow started:', workflowId);
54+
55+
const result = await linkedapi.createPost.result(workflowId);
56+
if (result.errors.length > 0) {
57+
console.error('🚨 Errors:', JSON.stringify(result.errors, null, 2));
58+
} else {
59+
console.log('✅ Post with images created successfully');
60+
console.log('🔗 Post URL:', result.data?.postUrl);
61+
}
62+
}
63+
64+
async function createCompanyPost(linkedapi: LinkedApi): Promise<void> {
65+
console.log('\n🏢 Creating a company page post with document...');
66+
67+
const workflowId = await linkedapi.createPost.execute({
68+
text: 'Download our latest whitepaper on AI trends in 2026',
69+
companyUrl: 'https://www.linkedin.com/company/acme-corp',
70+
attachments: [
71+
{
72+
url: 'https://example.com/whitepaper.pdf',
73+
type: 'document',
74+
name: 'AI Trends 2026 Whitepaper',
75+
},
76+
],
77+
});
78+
console.log('🏢 Create company post workflow started:', workflowId);
79+
80+
const result = await linkedapi.createPost.result(workflowId);
81+
if (result.errors.length > 0) {
82+
console.error('🚨 Errors:', JSON.stringify(result.errors, null, 2));
83+
} else {
84+
console.log('✅ Company post created successfully');
85+
console.log('🔗 Post URL:', result.data?.postUrl);
86+
}
87+
}
88+
2389
async function reactToPost(linkedapi: LinkedApi): Promise<void> {
2490
console.log('\n👍 Reacting to post...');
2591

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": "linkedapi-node",
3-
"version": "1.2.9",
3+
"version": "1.2.10",
44
"description": "Control your LinkedIn accounts and retrieve real-time data, all through this Node.js SDK.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/core/operation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const OPERATION_NAME = {
2929
fetchPost: 'fetchPost',
3030
reactToPost: 'reactToPost',
3131
commentOnPost: 'commentOnPost',
32+
createPost: 'createPost',
3233
retrieveSSI: 'retrieveSSI',
3334
retrievePerformance: 'retrievePerformance',
3435
nvSendMessage: 'nvSendMessage',

src/index.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { TMappedResponse } from './mappers/base-mapper.abstract';
44
import {
55
CheckConnectionStatus,
66
CommentOnPost,
7+
CreatePost,
78
CustomWorkflow,
89
FetchCompany,
910
FetchPerson,
@@ -101,6 +102,7 @@ class LinkedApi {
101102
this.fetchPost = new FetchPost(this.httpClient);
102103
this.reactToPost = new ReactToPost(this.httpClient);
103104
this.commentOnPost = new CommentOnPost(this.httpClient);
105+
this.createPost = new CreatePost(this.httpClient);
104106
this.retrieveSSI = new RetrieveSSI(this.httpClient);
105107
this.retrievePerformance = new RetrievePerformance(this.httpClient);
106108
this.nvSendMessage = new NvSendMessage(this.httpClient);
@@ -127,6 +129,7 @@ class LinkedApi {
127129
this.fetchPost,
128130
this.reactToPost,
129131
this.commentOnPost,
132+
this.createPost,
130133
this.retrieveSSI,
131134
this.retrievePerformance,
132135
this.nvSendMessage,
@@ -912,6 +915,63 @@ class LinkedApi {
912915
*/
913916
public commentOnPost: CommentOnPost;
914917

918+
/**
919+
* Create a LinkedIn post on your personal profile or a company page.
920+
*
921+
* This method creates a new post on LinkedIn. Posts can include text (up to 3,000 characters)
922+
* and optional media attachments (images, videos, or documents). For company posts, you must
923+
* have admin access to the company page.
924+
*
925+
* @param params - Parameters including post text, optional attachments, and optional company URL
926+
* @returns Promise resolving to an object containing the created post URL
927+
*
928+
* @see {@link https://linkedapi.io/docs/action-st-create-post/ st.createPost Action Documentation}
929+
*
930+
* @example
931+
* ```typescript
932+
* // Create a simple text post
933+
* const workflowId = await linkedapi.createPost.execute({
934+
* text: "Excited to share our latest product updates!\n\n#innovation"
935+
* });
936+
*
937+
* const result = await linkedapi.createPost.result(workflowId);
938+
* if (result.data) {
939+
* console.log("Post created:", result.data.postUrl);
940+
* }
941+
* ```
942+
*
943+
* @example
944+
* ```typescript
945+
* // Create a post with image attachments
946+
* const workflowId = await linkedapi.createPost.execute({
947+
* text: "Check out these amazing photos from our team event!",
948+
* attachments: [
949+
* { url: "https://example.com/photo1.jpg", type: "image" },
950+
* { url: "https://example.com/photo2.jpg", type: "image" }
951+
* ]
952+
* });
953+
*
954+
* const result = await linkedapi.createPost.result(workflowId);
955+
* console.log("Post with images created:", result.data?.postUrl);
956+
* ```
957+
*
958+
* @example
959+
* ```typescript
960+
* // Create a company page post with a document
961+
* const workflowId = await linkedapi.createPost.execute({
962+
* text: "Download our latest whitepaper on AI trends",
963+
* companyUrl: "https://www.linkedin.com/company/acme-corp",
964+
* attachments: [
965+
* { url: "https://example.com/whitepaper.pdf", type: "document", name: "AI Trends 2025" }
966+
* ]
967+
* });
968+
*
969+
* const result = await linkedapi.createPost.result(workflowId);
970+
* console.log("Company post created:", result.data?.postUrl);
971+
* ```
972+
*/
973+
public createPost: CreatePost;
974+
915975
/**
916976
* Retrieve your LinkedIn Social Selling Index (SSI) score.
917977
*

src/operations/create-post.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Operation, TOperationName } from '../core';
2+
import { SimpleWorkflowMapper } from '../mappers';
3+
import { TCreatePostParams, TCreatePostResult } from '../types';
4+
5+
export class CreatePost extends Operation<TCreatePostParams, TCreatePostResult> {
6+
public override readonly operationName: TOperationName = 'createPost';
7+
protected override readonly mapper = new SimpleWorkflowMapper<
8+
TCreatePostParams,
9+
TCreatePostResult
10+
>({
11+
actionType: 'st.createPost',
12+
});
13+
}

src/operations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export * from './retrieve-connections';
2020
export * from './remove-connection';
2121
export * from './react-to-post';
2222
export * from './comment-on-post';
23+
export * from './create-post';
2324
export * from './retrieve-ssi';
2425
export * from './retrieve-performance';

src/types/actions/post.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,26 @@ export type TFetchPostParams<T extends TBaseFetchPostParams = TBaseFetchPostPara
123123
};
124124

125125
export type TFetchPostResult = TPost;
126+
127+
export const ATTACHMENT_TYPE = {
128+
image: 'image',
129+
video: 'video',
130+
document: 'document',
131+
} as const;
132+
export type TAttachmentType = (typeof ATTACHMENT_TYPE)[keyof typeof ATTACHMENT_TYPE];
133+
134+
export interface TCreatePostAttachment {
135+
url: string;
136+
type: TAttachmentType;
137+
name?: string;
138+
}
139+
140+
export interface TCreatePostParams extends TBaseActionParams {
141+
text: string;
142+
attachments?: ReadonlyArray<TCreatePostAttachment>;
143+
companyUrl?: string;
144+
}
145+
146+
export interface TCreatePostResult {
147+
postUrl: string;
148+
}

0 commit comments

Comments
 (0)