# searchPosts

This method allows you to search for posts applying various filtering criteria.

```typescript
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", urn: "urn:li:member:251749025" }
      ],
      fromCompanies: ["Example Company"],
      mentioningMembers: [
        { name: "Example Person", personHashedUrl: "https://www.linkedin.com/in/ACoAAAKKvC4BR-qLHi0BnO-dJ8CP81tLsY0kKyc" }
      ],
      mentioningCompanies: [
        { name: "Another Company", companyHashedUrl: "https://www.linkedin.com/company/12345678" }
      ],
      authorCompanies: [
        { name: "Example Company", urn: "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);
  }
}
```

```python
from linkedapi import SearchPostsParams, LinkedApiError

try:
    workflow = linkedapi.search_posts.execute(
        SearchPostsParams(
            term="climate tech",
            limit=20,
            filter={
                "sort": "latest",
                "date_posted": "pastWeek",
                "content_type": "images",
                "posted_by": ["firstConnections", "peopleYouFollow"],
                "from_members": [
                    {"name": "Bill Gates", "urn": "urn:li:member:251749025"}
                ],
                "from_companies": ["Example Company"],
                "mentioning_members": [
                    {
                        "name": "Example Person",
                        "person_hashed_url": "https://www.linkedin.com/in/ACoAAAKKvC4BR-qLHi0BnO-dJ8CP81tLsY0kKyc",
                    }
                ],
                "mentioning_companies": [
                    {
                        "name": "Another Company",
                        "company_hashed_url": "https://www.linkedin.com/company/12345678",
                    }
                ],
                "author_companies": [
                    {"name": "Example Company", "urn": "urn:li:organization:1234567"}
                ],
                "author_industries": ["Software Development"],
            },
            custom_search_url="https://www.linkedin.com/search/results/content/?keywords=climate%20tech",
        )
    )

    result = linkedapi.search_posts.result(workflow.workflow_id)
    data = result.data
    errors = result.errors

    # The list of possible execution errors is below
    if errors:
        print("Workflow completed with execution errors:")
        for error in errors:
            print(f" - Type: {error.type}, Message: {error.message}")

    # The structure of the 'data' object is below
    if data:
        print("Workflow completed successfully. Data:", data)
except LinkedApiError as e:
    # A list of all critical errors can be found here:
    # https://linkedapi.io/sdks/handling-results-and-errors/#handling-critical-errors
    print(f"Critical Error - Type: {e.type}, Message: {e.message}")
except Exception as error:
    print("An unexpected, non-API error occurred:", error)
```

## Params

- `term` (optional) – keyword or phrase to search, from 1 to 50 characters. Either `term` or `customSearchUrl` must 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 than `limit`, 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 using `AND` logic. Ignored entirely when `customSearchUrl` is specified.
  - `sort` (optional) – one of `topMatch`, `latest`.
  - `datePosted` (optional) – one of `past24Hours`, `pastWeek`, `pastMonth`.
  - `contentType` (optional) – one of `videos`, `images`, `jobPosts`, `liveVideos`, `documents`.
  - `postedBy` (optional) – array of `me`, `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, `filter` is 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.

The five person and company filters all take the same entry shape. A plain string is shorthand for the name alone, so `["Bill Gates"]` and `[{ name: "Bill Gates" }]` mean the same thing, and both forms can be mixed in one array. Here is one array using every accepted form at once, and the company filters take the same four forms with `urn:li:organization:<id>` and `companyHashedUrl` in place of the member ones:

```typescript
const filter = {
  fromMembers: [
    "Bill Gates",
    { name: "Satya Nadella" },
    { name: "Example Person", urn: "urn:li:member:251749025" },
    {
      name: "Another Person",
      personHashedUrl: "https://www.linkedin.com/in/ACoAAAKKvC4BR-qLHi0BnO-dJ8CP81tLsY0kKyc"
    }
  ],
  fromCompanies: [
    "Microsoft",
    { name: "Example Company" },
    { name: "Another Company", urn: "urn:li:organization:1234567" },
    {
      name: "Third Company",
      companyHashedUrl: "https://www.linkedin.com/company/12345678"
    }
  ]
};
```

```python
filter = {
    "from_members": [
        "Bill Gates",
        {"name": "Satya Nadella"},
        {"name": "Example Person", "urn": "urn:li:member:251749025"},
        {
            "name": "Another Person",
            "person_hashed_url": "https://www.linkedin.com/in/ACoAAAKKvC4BR-qLHi0BnO-dJ8CP81tLsY0kKyc",
        },
    ],
    "from_companies": [
        "Microsoft",
        {"name": "Example Company"},
        {"name": "Another Company", "urn": "urn:li:organization:1234567"},
        {
            "name": "Third Company",
            "company_hashed_url": "https://www.linkedin.com/company/12345678",
        },
    ],
}
```

- `name` (required) – name to type into the LinkedIn filter panel, from 1 to 100 characters.
- `urn` (optional) – [URN](/sdks/core-concepts#linkedin-urns) of the person (`urn:li:member:<id>`) or of the company (`urn:li:organization:<id>`).
- `personHashedUrl` (optional) – [hashed](/faq/what-are-hashed-url-and-public-url) LinkedIn URL of the person, in the member filters.
- `companyHashedUrl` (optional) – [hashed](/faq/what-are-hashed-url-and-public-url) LinkedIn URL of the company, in the company filters.

> **A name on its own does not guarantee the right person or company.** LinkedIn's filter panel accepts typed text and nothing else, so with `name` alone the entry that gets picked is whichever suggestion LinkedIn ranked first for that name – which may be a namesake rather than the entity you meant. Supply `urn`, `personHashedUrl`, or `companyHashedUrl` alongside `name` to pin the exact one.

> An identifier you supply is matched, never approximated – the action fails with `filterIdentityMismatch` instead of quietly filtering by a namesake.

## 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 of `original`, `repost`.
- `author` – original content creator, or `null` if the actor cannot be parsed.
  - For person authors: `type`, `name`, `profileUrl`, `headline`.
  - For company authors: `type`, `name`, `companyUrl`.
- `reposter` – person or company that reshared the post. Non-null only when `type` is `repost`.
  - For person reposters: `type`, `name`, `profileUrl`, `headline`.
  - For company reposters: `type`, `name`, `companyUrl`.
- `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.

> Unlike posts returned by [fetchPost](/sdks/fetch-post), the `author` and `reposter` of a search result carry **no** `urn` field. The URN is read from the post's own page, so fetch the post by its `url` when you need it.

## Errors

- `filterIdentityMismatch` – a person or company requested in the search filter was not among the options LinkedIn offered for that name. Raised when a filter entry carries `urn`, `personHashedUrl`, or `companyHashedUrl` and none of the suggestions LinkedIn offers for the typed name resolves to it, including when an `urn` and a hashed URL are supplied together but point to different entities. It does not mean the person or company is gone – the usual cause is a `name` that does not match the entity the identifier names, so correct the entry rather than retrying.
- `searchingNotAllowed` – LinkedIn has blocked performing the search due to exceeding limits or other restrictions.
