Skip to main content
POST
/
company
/
search
Search companies using SQL query
curl --request POST \
  --url https://api.datalegion.ai/company/search \
  --header 'API-Key: <api-key>' \
  --header 'Content-Type: application/json' \
  --data @- <<EOF
{
  "query": "SELECT * FROM companies WHERE industry ILIKE '%software%' AND size='1001-5000'",
  "limit": 10
}
EOF
{
  "matches": [
    {
      "company": {
        "legion_id": "c8a1b2c3-d4e5-6f7a-8b9c-0d1e2f3a4b5c",
        "name": {
          "cleaned": "stripe inc",
          "display": "Stripe",
          "raw": [
            "Stripe, Inc."
          ]
        },
        "domain": "stripe.com",
        "industry": "financial services",
        "type": "private",
        "size": "5001-10000",
        "founded": 2010,
        "linkedin_url": "https://www.linkedin.com/company/stripe",
        "linkedin_id": "2135371",
        "legion_employee_count": 8500,
        "legion_average_tenure": 28.4,
        "legion_employee_growth_rate": {
          "1m": 0.012,
          "3m": 0.035,
          "6m": 0.068,
          "12m": 0.125
        },
        "last_seen": "2026-01",
        "num_sources": 5
      }
    }
  ],
  "total": 3417
}

Query Format

Write a SELECT * FROM companies WHERE ... query. Do not include LIMIT or OFFSET clauses in the SQL — use the limit and offset parameters instead.
{
  "query": "SELECT * FROM companies WHERE industry ILIKE '%software%' AND legion_employee_count > 100",
  "limit": 5
}

Response Shape

{
  "matches": [ { "company": { "..." : "..." } } ],
  "total": 3417
}
  • matches — capped at the request’s limit (max 100).
  • total — the full row count matching your WHERE clause across the database, not just the returned page. Useful for account-sizing: query for “fintech companies founded after 2018” with limit: 1 and total tells you how many accounts exist. The companion Total-Count-Status response header is exact when the count succeeded; on extremely broad WHERE clauses the count subquery may time out, in which case the header is page and total is just the size of the returned page. Search responses do not include match_metadata (that field is only populated by /company/enrich).

Pagination

To page through results beyond the first 100, set offset to the number of rows to skip. Maximum offset is 10,000.
{
  "query": "SELECT * FROM companies WHERE industry ILIKE '%software%' AND legion_employee_count > 100",
  "limit": 100,
  "offset": 100
}
Ordering is deterministic within a build — the same request returns the same rows in the same order, so paged requests don’t overlap or skip rows. Builds run on a periodic cadence; ordering may change across builds, so paginate within a single client session, not across days.

Available Columns

Text Columns

ColumnDescription
name_cleanedNormalized company name (lowercased)
name_displayDisplay-ready company name (original casing preserved)
domainPrimary website domain
industryIndustry classification
headline_cleanedLinkedIn headline
description_cleanedCompany description

Numeric Columns

ColumnDescription
foundedYear founded
linkedin_followersLinkedIn follower count
linkedin_employee_countEmployee count from LinkedIn
legion_employee_countEmployee count from Data Legion
legion_average_tenureAverage employee tenure (months)

Enum Columns

ColumnValues
typeprivate, public, nonprofit, government_agency, educational
size1-10, 11-50, 51-200, 201-500, 501-1000, 1001-5000, 5001-10000, 10001+

Workforce Analytics Columns

ColumnDescription
legion_new_hire_count_1m / 3m / 6m / 12mNew hires in last 1/3/6/12 months
legion_attrition_count_1m / 3m / 6m / 12mDepartures in last 1/3/6/12 months
legion_employee_growth_rate_1m / 3m / 6m / 12mGrowth rate (%)
legion_turnover_rate_1m / 3m / 6m / 12mTurnover rate (%)

Cross-Table Columns

These columns search across related tables and are automatically rewritten to subqueries:
ColumnDescription
ticker_symbol / tickerStock ticker symbol
exchangeStock exchange
social_urlSocial media URLs
alt_domainAlternative domains

Example Queries

-- Software companies with 100+ employees
SELECT * FROM companies WHERE industry ILIKE '%software%' AND legion_employee_count > 100

-- Public companies in healthcare
SELECT * FROM companies WHERE type = 'public' AND industry ILIKE '%health%'

-- Fast-growing companies (20%+ growth in last 6 months)
SELECT * FROM companies WHERE legion_employee_growth_rate_6m > 20

-- Companies with high turnover
SELECT * FROM companies WHERE legion_turnover_rate_12m > 30 AND legion_employee_count > 50

Authorizations

API-Key
string
header
required

Body

application/json

Request model for SQL query-based company search.

query
string
required

SQL query against company data (must not contain LIMIT)

Required string length: 1 - 10000
limit
integer
required

Maximum results to return

Required range: 1 <= x <= 100
offset
integer
default:0

Number of results to skip for pagination (0-10000). Stable within a build; ordering may change across builds.

Required range: 0 <= x <= 10000
titlecase
boolean
default:false

If true, format text fields in title case (names, company names, locations). Raw fields, IDs, URLs, codes, and confidence fields are excluded.

include_fields
string | null

Comma-separated list of fields to include in response. If omitted, all fields are returned.

exclude_fields
string | null

Comma-separated list of fields to exclude from response. Applied after include_fields filter.

pretty_print
boolean
default:false

If true, pretty-print JSON response with indentation.

Response

Success - query executed and results returned

matches
CompanyMatchResponse · object[]
required

List of matches sorted by confidence (descending). Capped at the request's limit.

total
integer
required

For /company/search and /company/discover, the total number of rows matching the query's WHERE clause across the database (not just this page). For /company/enrich, the number of matches found for the input identifier. On search/discover, if the count subquery fails or times out, this falls back to the size of the returned page; the response header Total-Count-Status distinguishes the two cases.