Skip to content

Commit 832b67d

Browse files
committed
[BUG] 403 error when trying to create a simple text post in LinkedIn
1 parent 28e91bb commit 832b67d

File tree

5 files changed

+55
-39
lines changed

5 files changed

+55
-39
lines changed

components/linkedin/actions/create-image-post-organization/create-image-post-organization.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "linkedin-create-image-post-organization",
88
name: "Create Image Post (Organization)",
99
description: "Create an image post on LinkedIn. [See the documentation](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/images-api?view=li-lms-2023-09&tabs=http#uploading-an-image)",
10-
version: "1.0.2",
10+
version: "1.0.3",
1111
type: "action",
1212
props: {
1313
linkedin,
@@ -87,7 +87,11 @@ export default {
8787

8888
await this.linkedin.createPost({
8989
data: {
90-
author: this.organizationId,
90+
author: `urn:li:organization:${this.organizationId}`,
91+
lifecycleState: "PUBLISHED",
92+
distribution: {
93+
feedDistribution: "MAIN_FEED",
94+
},
9195
commentary: utils.escapeText(this.text),
9296
visibility: "PUBLIC",
9397
content: {

components/linkedin/actions/create-image-post-user/create-image-post-user.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "linkedin-create-image-post-user",
88
name: "Create Image Post (User)",
99
description: "Create an image post on LinkedIn. [See the documentation](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/images-api?view=li-lms-2023-09&tabs=http#uploading-an-image)",
10-
version: "1.0.2",
10+
version: "1.0.3",
1111
type: "action",
1212
props: {
1313
linkedin,
@@ -85,8 +85,17 @@ export default {
8585

8686
await this.uploadImage(uploadUrl, formData);
8787

88+
const { id } = await this.linkedin.getCurrentMemberProfile({
89+
$,
90+
});
91+
8892
await this.linkedin.createPost({
8993
data: {
94+
author: `urn:li:person:${id}`,
95+
lifecycleState: "PUBLISHED",
96+
distribution: {
97+
feedDistribution: "MAIN_FEED",
98+
},
9099
commentary: utils.escapeText(this.text),
91100
visibility: this.visibility,
92101
content: {

components/linkedin/actions/create-text-post-user/create-text-post-user.mjs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "linkedin-create-text-post-user",
66
name: "Create a Simple Post (User)",
77
description: "Create post on LinkedIn using text, URL or article. [See the documentation](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api?view=li-lms-2022-11&tabs=http#create-organic-posts) for more information",
8-
version: "0.0.7",
8+
version: "0.0.8",
99
type: "action",
1010
props: {
1111
linkedin,
@@ -29,23 +29,43 @@ export default {
2929
},
3030
},
3131
async run({ $ }) {
32-
const data = {
33-
commentary: utils.escapeText(this.text),
34-
visibility: this.visibility,
35-
};
36-
if (this.article) {
37-
data.content = {
38-
article: {
39-
source: this.article,
40-
title: this.article,
41-
},
42-
};
43-
}
44-
const response = await this.linkedin.createPost({
32+
const {
33+
linkedin,
34+
visibility,
35+
text,
36+
article,
37+
} = this;
38+
39+
const profile = await linkedin.getCurrentMemberProfile({
40+
$,
41+
});
42+
43+
const response = await linkedin.createPost({
4544
$,
46-
data,
45+
data: {
46+
author: `urn:li:person:${profile?.id}`,
47+
lifecycleState: "PUBLISHED",
48+
distribution: {
49+
feedDistribution: "MAIN_FEED",
50+
},
51+
commentary: utils.escapeText(text),
52+
visibility,
53+
...(article
54+
? {
55+
content: {
56+
article: {
57+
source: article,
58+
title: article,
59+
},
60+
},
61+
}
62+
: {}
63+
),
64+
},
4765
});
4866
$.export("$summary", "Successfully created a new Post as User");
49-
return response;
67+
return response || {
68+
success: true,
69+
};
5070
},
5171
};

components/linkedin/linkedin.app.mjs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,10 @@ export default {
157157
...otherConfig,
158158
});
159159
},
160-
async createPost({
161-
data, ...args
162-
}) {
163-
data = {
164-
...data,
165-
author: `urn:li:${data?.author
166-
? "organization"
167-
: "person"}:${data.author || this.$auth.oauth_uid}`,
168-
lifecycleState: "PUBLISHED",
169-
distribution: {
170-
feedDistribution: "MAIN_FEED",
171-
},
172-
};
160+
createPost(args = {}) {
173161
return this._makeRequest({
174162
method: "POST",
175163
path: "/posts",
176-
data,
177164
...args,
178165
});
179166
},

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)