createPost
This method allows you to publish a post, optionally with media attachments and mentions of people and companies.
try {
const workflow = await linkedapi.createPost.execute({
text: "Huge thanks to @[author] for the write-up!",
mentions: [
{
key: "author",
name: "Example Person",
personHashedUrl: "https://www.linkedin.com/in/ACwAAAxxxxxxxxx"
}
],
attachments: [
{
url: "https://example.com/images/team-photo.jpg",
type: "image"
}
],
companyUrl: "https://www.linkedin.com/company/company1"
});
const { data, errors } = await linkedapi.createPost.result(workflow.workflowId);
// The list of possible execution errors is below
if (errors && errors.length > 0) {
console.warn('Workflow completed with execution errors:');
errors.forEach(error => {
console.warn(` - Type: ${error.type}, Message: ${error.message}`);
});
}
// The structure of the 'data' object is below
if (data) {
console.log('Workflow completed successfully. Data:', data);
}
} catch (e) {
// A list of all critical errors can be found here:
// https://linkedapi.io/sdks/handling-results-and-errors/#handling-critical-errors
if (e instanceof LinkedApiError) {
console.error(`Critical Error - Type: ${e.type}, Message: ${e.message}`);
} else {
console.error('An unexpected, non-API error occurred:', e);
}
}Params
text– post text, must be up to 3000 characters.mentions(optional) – people and companies to mention in the text. Write@[key]where the mention should appear, and describe thatkeyhere.key– the placeholder name used in the text as@[key]. From 1 to 30 characters: letters, digits,_or-.name– the name to find the person or company by, from 1 to 100 characters.urn(optional) – LinkedIn URN of the entity:urn:li:member:<id>for a person,urn:li:organization:<id>for a company.personHashedUrl(optional) – hashed LinkedIn profile URL of the person.companyHashedUrl(optional) – hashed LinkedIn company page URL.
attachments(optional) – array of media attachments. Maximum 9 items.url– publicly accessible URL of the file to attach.type– type of attachment:image,video, ordocument.name(required when type isdocument) – display name for the document.
companyUrl(optional) – LinkedIn company page URL. When provided, the post will be published on behalf of the company. Requires content admin access to the company page.
At most 20 mentions per post, at most one of urn, personHashedUrl and companyHashedUrl per mention, no two mentions sharing a key, and every @[key] in the text matched by exactly one mention and vice versa. Breaking any of these rejects the workflow before anything is published.
name is required even when you provide an identifier, because LinkedIn resolves a mention through its own name suggestions: the identifier decides which of the offered namesakes is taken, and without one the first suggestion LinkedIn ranks is used. The published mention shows LinkedIn's own name for the entity, which may differ from the name you sent.
Attachment limits: up to 9 images (JPEG, PNG, GIF, WebP, max 8 mb), or 1 video (MP4, MOV, WebM, max 200 mb), or 1 document (PDF, max 100 mb). Different attachment types cannot be mixed.
Data
postUrl– URL of the created post.postUrn– LinkedIn URN of the created post. It can be used as thepostUrninput for any post method.
Both fields are
nullwhen the post was published but LinkedIn did not return its address. Do not retry: the post is already live.
Errors
textTooLong– post text exceeds 3000 characters limit.companyNotFound– specified company page was not found on LinkedIn.noPostingPermission– no permission to post on behalf of this company.mentionNotResolved– a person or company the text mentions was not among the options LinkedIn offered for that name. Nothing was published.unsupportedAttachmentType– attachment type is not supported. Useimage,video, ordocument.missingDocumentName– document attachment requires anamefield.urlNotAccessible– attachment URL is not publicly accessible or returned an error.fileTooLarge– attachment file exceeds the maximum allowed size.unsupportedMimeType– file's MIME type is not supported by LinkedIn.tooManyAttachments– more than 9 attachments were provided.mixingNotAllowed– cannot mix different attachment types.