searchPosts
This method allows you to search for posts applying various filtering criteria.
try {
const workflow = await linkedapi.searchPosts.execute({
term: "climate tech",
limit: 20,
filter: {
sort: "latest",
datePosted: "pastWeek",
contentType: "images",
postedBy: ["firstConnections", "peopleYouFollow"],
fromMembers: [
{ name: "Bill Gates", id: "urn:li:member:251749025" }
],
fromCompanies: ["Example Company"],
mentioningMembers: [
{ name: "Example Person", id: "https://www.linkedin.com/in/example-person" }
],
mentioningCompanies: [
{ name: "Another Company", id: "https://www.linkedin.com/company/another-company" }
],
authorCompanies: [
{ name: "Example Company", id: "urn:li:organization:1234567" }
],
authorIndustries: ["Software Development"]
},
customSearchUrl: "https://www.linkedin.com/search/results/content/?keywords=climate%20tech"
});
const { data, errors } = await linkedapi.searchPosts.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
term(optional) – keyword or phrase to search, from 1 to 50 characters. EithertermorcustomSearchUrlmust be provided.limit(optional) – number of search results to return. Defaults to 10, with a maximum value of 100, or 20 when child actions are used. A value above the applicable maximum is rejected when the workflow is submitted. A search may return fewer posts thanlimit, because how many results come back depends on what LinkedIn loads for that account on that search.filter(optional) – filtering criteria for posts. Every specified field is applied, or the action fails. When multiple filter fields are specified, they are combined usingANDlogic. Ignored entirely whencustomSearchUrlis specified.sort(optional) – one oftopMatch,latest.datePosted(optional) – one ofpast24Hours,pastWeek,pastMonth.contentType(optional) – one ofvideos,images,jobPosts,liveVideos,documents.postedBy(optional) – array ofme,firstConnections,peopleYouFollow.fromMembers(optional) – array of people whose posts to keep.fromCompanies(optional) – array of companies whose posts to keep.mentioningMembers(optional) – array of people to look for in post text.mentioningCompanies(optional) – array of companies to look for in post text.authorCompanies(optional) – array of companies the author works at.authorIndustries(optional) – array of industry names the author works in. An industry is a taxonomy value rather than an entity, so it is matched by name only.
customSearchUrl(optional) – URL copied from a LinkedIn content search page after configuring filters. When specified,filteris ignored entirely and the facets already encoded in the URL are the only ones applied.
LinkedIn widens a narrow query on its own and returns loosely related posts, so a non-empty result does not mean your term matched. Check the returned posts against your own criteria when an exact match matters.
Each entry of fromMembers, fromCompanies, mentioningMembers, mentioningCompanies, and authorCompanies is a name, or a name with an id:
const filter = {
fromMembers: [
"Bill Gates",
{ name: "Satya Nadella", id: "https://www.linkedin.com/in/satyanadella" }
],
fromCompanies: [
"Microsoft",
{ name: "Example Company", id: "urn:li:organization:1234567" }
]
};name(required) – name of the person or company as typed into LinkedIn's filter panel, from 1 to 100 characters. Whenidis a member URN or a Sales Navigator URL, the person must appear among LinkedIn's suggestions for this name.id(optional) – URN, public or hashed LinkedIn URL (Sales Navigator URLs included), or, for a company, numeric ID. Pins the filter to exactly that person or company. A person's public URL is opened once from your account to read their identifier, so they may see one profile visit; a company's public URL is opened on every search, so prefer its URN or numeric ID.
A name alone may match a namesake: Linked API takes the LinkedIn suggestion whose name matches yours, ignoring case, punctuation and a trailing legal form such as
IncorGmbH, or else the first one that starts with it as a whole word, soAntacan becomeAnta Internationalbut neverAntal. If no suggestion matches, the action fails withfilterNotApplied.
Data
Array of search results. Each search result contains:
url– URL of the post.activityUrn– LinkedIn activity or UGC URN of the post, if available.time– timestamp when the post was published.type– one oforiginal,repost.author– original content creator, ornullif the actor cannot be parsed.- For person authors:
type,name,profileUrl,headline,viewerStatewithconnectionDegree–1st,2nd,3rd+, ornullif LinkedIn does not show it (see viewer state). - For company authors:
type,name,companyUrl.
- For person authors:
reposter– person or company that reshared the post. Non-null only whentypeisrepost.- For person reposters:
type,name,profileUrl,headline. - For company reposters:
type,name,companyUrl.
- For person reposters:
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– whether the post contains a video.videoThumbnail– URL of the video thumbnail, if available.hasPoll– whether 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), ornullif you have not reacted or it could not be read.isOwn–trueif your account is the post author,falseif someone else is, ornullif this cannot be told.
Unlike posts returned by fetchPost, the
authorandreposterof a search result carry nournfield. The URN is read from the post's own page, so fetch the post by itsurlwhen you need it.
Errors
filterNotApplied– one or more filter values could not be applied: no LinkedIn option matched a name, or the person or company anidnames could not be found or is not among LinkedIn's suggestions forname. It does not mean the person or company is gone; the message lists each field, value, and reason, so correct or remove the entry rather than retrying.searchingNotAllowed– LinkedIn has blocked performing the search due to exceeding limits or other restrictions.