> ## Documentation Index
> Fetch the complete documentation index at: https://docs.harvestapi.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Search Leads

> Search LinkedIn profile leads by filters with advanced inclusion and exclusion criteria

* This is the same search as used in [the Profile Search Apify Actor](https://apify.com/harvestapi/linkedin-profile-search)
  and in the [Company Employees Search](https://apify.com/harvestapi/linkedin-company-employees) - it's possible to replicate
  features of these actors using this API endpoint.

## Examples

<CodeGroup>
  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({
    page: '1',
    search: 'Machine Learning Engineer',
    currentCompany: 'https://www.linkedin.com/company/google',
    location: 'US',
    seniorityLevelIds: '120,210',
    profileLanguages: 'en',
    excludeSeniorityLevelIds: '220,300,310',
  });
  fetch(`https://api.harvestapi.io/linkedin/lead-search?${params.toString()}`, {
    headers: { 'X-API-Key': '<api-key>' },
  })
    .then((response) => response.json())
    .then((data) => console.log(data));
  ```
</CodeGroup>

## Session ID

* LinkedIn applies search personalization, so the results may vary based on resources used for scraping.
* When iterating over multiple pages, different pages might be scraped by different resources, which can lead to inconsistent results.

To mitigate this, you can use the `sessionId` parameter to request our backend to use the same resource.\
To create a `sessionId`, you can generate a random string (e.g., using UUID) and pass it as a query parameter in your API request.\
This `sessionId` will not be passed to LinkedIn, it is used only internally in our backend to identify which requests should be processed by the same resource. Our backend tracks LinkedIn's `sessionId` independently.

In case if the initially assigned resource becomes unavailable (rate-limited, proxy offline, etc.), our backend will reassign the session to a different resource.

Using `sessionId` slows requests down, as multiple users (or even different sessions) can be acquiring the same resource. Since our resources can process only one request at a time, requests with `sessionId` will be queued until the resource is available to take a new request.


## OpenAPI

````yaml GET /linkedin/lead-search
openapi: 3.0.1
info:
  title: HarvestAPI LinkedIn API reference
  description: HarvestAPI LinkedIn API reference
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.harvestapi.io
security:
  - ApiKeyAuthHeader: []
paths:
  /linkedin/lead-search:
    get:
      summary: Search LinkedIn leads
      description: >-
        Search LinkedIn profile leads by filters with advanced inclusion and
        exclusion criteria
      parameters:
        - name: search
          in: query
          description: Search query. Fuzzy search, supports LinkedIn's search operators
          schema:
            type: string
        - name: currentCompanies
          in: query
          description: Filter by current company IDs or URLs. Comma-separated (max 50)
          schema:
            type: string
        - name: pastCompanies
          in: query
          description: Filter by past company IDs or URLs. Comma-separated (max 50)
          schema:
            type: string
        - name: locations
          in: query
          description: Filter by location text. Comma-separated (max 70)
          schema:
            type: string
        - name: geoIds
          in: query
          description: >-
            Filter by LinkedIn Geo ID. Comma-separated. Overrides location
            param. Use /linkedin/geo-id-search to find IDs
          schema:
            type: string
        - name: schools
          in: query
          description: Filter by school IDs or URLs. Comma-separated (max 50)
          schema:
            type: string
        - name: currentJobTitles
          in: query
          description: Filter by current job titles. Comma-separated (max 70)
          schema:
            type: string
        - name: pastJobTitles
          in: query
          description: Filter by past job titles. Comma-separated (max 70)
          schema:
            type: string
        - name: firstNames
          in: query
          description: Filter by first names. Comma-separated (max 70)
          schema:
            type: string
        - name: lastNames
          in: query
          description: Filter by last names. Comma-separated (max 70)
          schema:
            type: string
        - name: industryIds
          in: query
          description: >-
            Filter by industry IDs. Comma-separated (max 70). Full list:
            https://github.com/HarvestAPI/linkedin-industry-codes-v2/blob/main/linkedin_industry_code_v2_all_eng_with_header.csv
          schema:
            type: string
        - name: yearsAtCurrentCompanyIds
          in: query
          description: >-
            Filter by years at current company IDs. Comma-separated.
            https://github.com/HarvestAPI/harvestapi-sdk/blob/main/packages/scraper/README.md#yearsatcurrentcompanyids
          schema:
            type: string
        - name: yearsOfExperienceIds
          in: query
          description: >-
            Filter by years of experience IDs. Comma-separated.
            https://github.com/HarvestAPI/harvestapi-sdk/blob/main/packages/scraper/README.md#yearsofexperienceids
          schema:
            type: string
        - name: seniorityLevelIds
          in: query
          description: >-
            Filter by seniority level IDs. Comma-separated.
            https://github.com/HarvestAPI/harvestapi-sdk/blob/main/packages/scraper/README.md#senioritylevelids
          schema:
            type: string
        - name: functionIds
          in: query
          description: >-
            Filter by job function IDs. Comma-separated.
            https://github.com/HarvestAPI/harvestapi-sdk/blob/main/packages/scraper/README.md#functionids
          schema:
            type: string
        - name: recentlyChangedJobs
          in: query
          description: Filter leads who recently changed jobs in the last 90 days.
          schema:
            type: boolean
        - name: postedOnLinkedin
          in: query
          description: Filter leads who posted on LinkedIn in the last 30 days
          schema:
            type: boolean
        - name: profileLanguages
          in: query
          description: >-
            Filter by profile languages. Comma-separated.
            https://github.com/HarvestAPI/harvestapi-sdk/blob/main/packages/scraper/README.md#profilelanguages
          schema:
            type: string
        - name: companyHeadcount
          in: query
          description: >-
            Filter by company headcount. Comma-separated.
            https://github.com/HarvestAPI/harvestapi-sdk/blob/main/packages/scraper/README.md#companyheadcount
          schema:
            type: string
        - name: companyHeadquarterLocations
          in: query
          description: >-
            Filter by company headquarter location text. Comma-separated (max
            70)
          schema:
            type: string
        - name: excludeLocations
          in: query
          description: Locations to exclude from search. Comma-separated (max 70)
          schema:
            type: string
        - name: excludeGeoIds
          in: query
          description: Geo IDs to exclude from search. Comma-separated (max 70)
          schema:
            type: string
        - name: excludeCurrentCompanies
          in: query
          description: Current companies to exclude. Comma-separated (max 50)
          schema:
            type: string
        - name: excludePastCompanies
          in: query
          description: Past companies to exclude. Comma-separated (max 50)
          schema:
            type: string
        - name: excludeSchools
          in: query
          description: Schools to exclude. Comma-separated (max 50)
          schema:
            type: string
        - name: excludeCurrentJobTitles
          in: query
          description: Current job titles to exclude. Comma-separated (max 70)
          schema:
            type: string
        - name: excludePastJobTitles
          in: query
          description: Past job titles to exclude. Comma-separated (max 70)
          schema:
            type: string
        - name: excludeIndustryIds
          in: query
          description: Industry IDs to exclude. Comma-separated (max 70)
          schema:
            type: string
        - name: excludeSeniorityLevelIds
          in: query
          description: Seniority level IDs to exclude. Comma-separated (max 20)
          schema:
            type: string
        - name: excludeFunctionIds
          in: query
          description: Function IDs to exclude. Comma-separated (max 30)
          schema:
            type: string
        - name: excludeCompanyHeadquarterLocations
          in: query
          description: >-
            Company headquarter locations to exclude from search.
            Comma-separated (max 70)
          schema:
            type: string
        - name: salesNavUrl
          in: query
          description: >-
            LinkedIn Sales Navigator search URL to use for the search. This will
            override all other search parameters, except the `page` parameter.
            For pagination, please pass the `page` query parameter separately. 

            Note: the scraper doesn't scrape the URL directly, it will parse the
            URL, sanitize and validate params. It supports all parameters
            currently, but if LinkedIn adds new parameters in the future, they
            might not be supported until we update the API. Please contact us in
            this case.
          schema:
            type: string
        - name: page
          in: query
          description: Page number for pagination (clamped at 100)
          schema:
            type: integer
            default: 1
        - name: sessionId
          in: query
          description: >-
            Session ID to use for the search. See
            https://docs.harvestapi.io/linkedin-api-reference/leads/search-leads#session-id
            for details.
          schema:
            type: string
        - name: usePrivatePool
          in: query
          description: Set to true to use your private pool of resources (if available)
          schema:
            type: string
        - name: requiredAccountId
          in: query
          description: >-
            If we provide you a private pool of accounts, you can use this
            parameter to specify which account should be used for this request.
          schema:
            type: string
      responses:
        '200':
          description: Lead search response
          content:
            application/json:
              schema:
                type: object
                properties:
                  elements:
                    type: array
                    items:
                      $ref: '#/components/schemas/LeadShort'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
                  status:
                    type: string
                  error:
                    type: string
        '400':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    LeadShort:
      required:
        - linkedinUrl
      type: object
      properties:
        id:
          type: string
        linkedinUrl:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        openProfile:
          type: boolean
        premium:
          type: boolean
        location:
          type: object
          properties:
            linkedinText:
              type: string
        pictureUrl:
          type: string
        currentPositions:
          type: array
          items:
            type: object
            properties:
              companyName:
                type: string
              title:
                type: string
              description:
                type: string
              startedOn:
                type: object
                properties:
                  month:
                    type: string
                    format: nullable
                  year:
                    type: integer
                    format: int32
              companyId:
                type: string
              companyLinkedinUrl:
                type: string
              tenureAtPosition:
                type: object
                properties:
                  numYears:
                    type: string
                  numMonths:
                    type: string
              tenureAtCompany:
                type: object
                properties:
                  numYears:
                    type: string
                  numMonths:
                    type: string
    Pagination:
      type: object
      properties:
        totalPages:
          type: integer
          format: int32
        totalElements:
          type: integer
          format: int32
        pageNumber:
          type: integer
          format: int32
        previousElements:
          type: integer
          format: int32
        pageSize:
          type: integer
          format: int32
        paginationToken:
          type: string
          format: nullable
    Error:
      required:
        - error
        - message
      type: object
      properties:
        error:
          type: integer
          format: int32
        message:
          type: string
  securitySchemes:
    ApiKeyAuthHeader:
      type: apiKey
      in: header
      name: X-API-Key

````