fetchPost

This method allows you to retrieve post data.

typescript
try {
  const workflow = await linkedapi.fetchPost.execute({
    postUrl: "https://www.linkedin.com/posts/username_activity-id",
    retrieveComments: true,
    retrieveReactions: true,
    commentsRetrievalConfig: {
      limit: 20,
      replies: true,
      sort: 'mostRecent'
    },
    reactionsRetrievalConfig: {
      limit: 50,
    },
  });

  const { data, errors } = await linkedapi.fetchPost.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

  • postUrl – LinkedIn URL of the post.
  • postUrn (optional) – LinkedIn URN of the post, accepted instead of postUrl. When both are provided, the URL must contain that same URN.
  • retrieveComments (optional) – when set to true, includes comments on the post in the results.
  • retrieveReactions (optional) – when set to true, includes reactions on the post in the results.
  • commentsRetrievalConfig (optional) – configuration for retrieving comments. Available only if retrieveComments is true.
    • replies (optional, default: false) – when set to true, the action includes replies to the comments in the results.
    • limit (optional) – number of comments to retrieve. Also applies to the replies if replies set to true. Defaults to 10, with a maximum value of 500.
    • sort (optional, default: mostRelevant) – enum representing comments sorting. Options:
      • mostRelevant – show most relevant comments first.
      • mostRecent – show most recent comments first.
  • reactionsRetrievalConfig (optional) – configuration for retrieving reactions. Available only if retrieveReactions is true.
    • limit (optional) – number of reactions to retrieve. Defaults to 10, with a maximum value of 500.

Data

  • url – URL of the post.
  • activityUrn – LinkedIn activity or UGC URN of the post, if available.
  • time – timestamp when the post was published.
  • type – type of the post. Enum with possible values:
    • original – for original posts.
    • repost – for reposts.
  • author – original content creator. Can be null if the actor cannot be parsed.
    • For person authors: type, name, urn, profileUrl, headline, viewerState with connectionDegree – 1st, 2nd, 3rd+, or null if LinkedIn does not show it (see viewer state).
    • For company authors: type, name, urn, companyUrl.
  • reposter – person or company that reshared the post. Non-null only when type is repost.
    • For person reposters: type, name, urn, profileUrl, headline.
    • For company reposters: type, name, urn, companyUrl.
  • urn on an actor – URN of that person or company, or null when LinkedIn does not expose an identifier for the actor.
  • text – original author's post text, if available.
  • repostText – text added by the reposter on a repost with comment, if available.
  • hashtags – array of hashtags found in the post text, without leading #.
  • mentions – array of person and company profile URLs found in the post text.
  • externalLinks – array of outbound URLs found in the post text.
  • images – array of up to 3 preview image URLs, if available.
  • documentSlides – array of carousel or document slide image URLs, if available.
  • hasVideo – boolean indicating if the post contains a video.
  • videoThumbnail – URL of the video thumbnail, if available.
  • hasPoll – boolean indicating if the post contains a poll.
  • reactionsCount – number of reactions on the post.
  • commentsCount – number of comments on the post.
  • repostsCount – number of reposts on the post.
  • viewerState – what your account has done with the post, see viewer state.
    • reaction – your reaction to the post (like, celebrate, support, love, insightful, funny), or null if you have not reacted or it could not be read.
    • isOwn – true if your account is the post author, false if someone else is, or null if this cannot be told.
  • comments – array of post comments (included only if retrieveComments is true).
    • commentUrn – LinkedIn URN of the comment, if available.
    • commentUrl – canonical deep-link URL of the comment, if available. It can be used as the commentUrl input for reactToComment or replyToComment.
    • author – person or company who wrote the comment.
      • For person authors: type, name, profileUrl, headline, viewerState with connectionDegree – 1st, 2nd, 3rd+, or null if LinkedIn does not show it, which is always the case for comments read in the feed or from LinkedIn's classic post layout (see viewer state).
      • For company authors: type, name, companyUrl.
    • commenterUrl – deprecated, use author instead. Public URL of the person or company.
    • commenterName – deprecated, use author.name. Full name of the person or company.
    • commenterHeadline – deprecated, use author.headline. Headline of the person or company.
    • commenterType – deprecated, use author.type. Commenter type. Enum with the following values:
      • person – commenter is a person.
      • company – commenter is a company.
    • time – free-form string indicating comment time. For example: 6d, 2w or 1y.
    • text – text content of the comment, if available.
    • image – URL of the comment's image, if available.
    • isReply – boolean value indicates if this comment is a reply to another comment.
    • reactionsCount – number of reactions on the comment.
    • repliesCount – number of replies on the comment. Always returns 0 if isReply is true.
    • viewerState – what your account has done with the comment, see viewer state.
      • reaction – your reaction to the comment (like, celebrate, support, love, insightful, funny), or null if you have not reacted or the page does not show it. Comments read in the feed or from LinkedIn's classic post layout always report null.
      • isOwn – true if your account wrote the comment, false if someone else did, or null if this cannot be told.
  • reactions – array of post reactions (included only if retrieveReactions is true).
    • engagerUrn – URN of the person or company, or null if LinkedIn does not expose it.
    • engagerUrl – URL of the person or company.
    • engagerName – full name of the person or company.
    • engagerHeadline – headline of the person or company.
    • engagerType – the engager type. Enum with the following values:
      • person – the engager is the person.
      • company – the engager is the company.
    • type – enum describing the reaction type. Possible values:
      • like – standard "like".
      • celebrate – to celebrate an achievement.
      • support – to show support.
      • love – to express love or admiration.
      • insightful – to appreciate insightful content.
      • funny – to react to something humorous.

Errors

  • postNotFound – provided URL is not an existing LinkedIn post.