curl --request POST \
--url https://api.datalegion.ai/company/search \
--header 'API-Key: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"limit": 10,
"sql": "SELECT * FROM companies WHERE industry ILIKE '%software%'"
}
EOFimport requests
url = "https://api.datalegion.ai/company/search"
payload = {
"limit": 10,
"sql": "SELECT * FROM companies WHERE industry ILIKE '%software%'"
}
headers = {
"API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({limit: 10, sql: 'SELECT * FROM companies WHERE industry ILIKE \'%software%\''})
};
fetch('https://api.datalegion.ai/company/search', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.datalegion.ai/company/search",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'limit' => 10,
'sql' => 'SELECT * FROM companies WHERE industry ILIKE \'%software%\''
]),
CURLOPT_HTTPHEADER => [
"API-Key: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.datalegion.ai/company/search"
payload := strings.NewReader("{\n \"limit\": 10,\n \"sql\": \"SELECT * FROM companies WHERE industry ILIKE '%software%'\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.datalegion.ai/company/search")
.header("API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"limit\": 10,\n \"sql\": \"SELECT * FROM companies WHERE industry ILIKE '%software%'\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalegion.ai/company/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"limit\": 10,\n \"sql\": \"SELECT * FROM companies WHERE industry ILIKE '%software%'\"\n}"
response = http.request(request)
puts response.read_body{
"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
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}Company Search API
Company Search API endpoint: query company profiles using SQL-like syntax with flexible filtering across 50+ data fields.
curl --request POST \
--url https://api.datalegion.ai/company/search \
--header 'API-Key: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"limit": 10,
"sql": "SELECT * FROM companies WHERE industry ILIKE '%software%'"
}
EOFimport requests
url = "https://api.datalegion.ai/company/search"
payload = {
"limit": 10,
"sql": "SELECT * FROM companies WHERE industry ILIKE '%software%'"
}
headers = {
"API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({limit: 10, sql: 'SELECT * FROM companies WHERE industry ILIKE \'%software%\''})
};
fetch('https://api.datalegion.ai/company/search', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.datalegion.ai/company/search",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'limit' => 10,
'sql' => 'SELECT * FROM companies WHERE industry ILIKE \'%software%\''
]),
CURLOPT_HTTPHEADER => [
"API-Key: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.datalegion.ai/company/search"
payload := strings.NewReader("{\n \"limit\": 10,\n \"sql\": \"SELECT * FROM companies WHERE industry ILIKE '%software%'\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.datalegion.ai/company/search")
.header("API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"limit\": 10,\n \"sql\": \"SELECT * FROM companies WHERE industry ILIKE '%software%'\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalegion.ai/company/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"limit\": 10,\n \"sql\": \"SELECT * FROM companies WHERE industry ILIKE '%software%'\"\n}"
response = http.request(request)
puts response.read_body{
"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
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}{
"error": "<string>",
"message": "<string>",
"details": {}
}Three Ways to Search
Send exactly one of these with each request:| Input | What it is | Best for |
|---|---|---|
filters | The record’s own field names with values, plus a Boolean keywords string | Most searches; no query language to learn |
sql | A SELECT * FROM companies WHERE ... statement | Analysts and data teams |
es_query | A query object in the Elasticsearch query syntax | Code that builds searches |
sql takes only SQL and es_query only a query object. The older query parameter still works (SQL as text, a query object as an object); new code should use the inputs above.
{
"filters": {
"industry": "software development",
"linkedin_employee_count": { "gte": 100 },
"locations.city": "austin",
"locations.primary": true
},
"limit": 5
}
{
"sql": "SELECT * FROM companies WHERE industry = 'software development' AND linkedin_employee_count >= 100 AND hq_city = 'austin'",
"limit": 5
}
Filters
Filter keys are the record’s own field names: the ones in every response and on the field reference. One grammar works for every field:| Value | Means | Example |
|---|---|---|
| A value | The field holds it | "industry": "software development" |
| A list | Any of them | "size": ["51-200", "201-500"] |
{"gte": .., "lte": ..} (also gt, lt) | A range, for numbers and dates | "linkedin_employee_count": {"gte": 100} |
{"exists": true} | The field holds a value (false: it doesn’t) | "tickers.symbol": {"exists": true} |
true / false | A flag | "locations.primary": true |
TX, us-tx and Texas are the same state).
A company’s offices are a list: fields under locations given together must hold for the same office. The headquarters is the office marked primary, so “headquartered in Austin” is {"locations.city": "austin", "locations.primary": true}; without locations.primary, any office on record counts.
A key that is not a field of the record is a 422 that names the closest real fields. Fields outside your plan are refused, as they are in SQL.
Combining Filters
To combine sets of fields, wrap them in a group, which is also how to rule something out:{"and": [...]} (all must hold), {"or": [...]} (any may hold) or {"not": {...}} (must not hold). Groups nest up to 3 levels, with up to 20 items in each.
{
"filters": {
"or": [
{ "industry": "software development", "size": "51-200" },
{ "keywords": "\"machine learning\" OR robotics", "locations.country_code": "GB" }
]
},
"limit": 10
}
Boolean Keywords
keywords takes a Boolean search string, written the way recruiters write one: words and "quoted phrases", with AND, OR and NOT in capitals and parentheses for grouping. Words side by side mean AND, and a lowercase “and” is just a word. NOT binds tightest, then AND, then OR, so python AND django OR flask means (python AND django) OR flask. It searches the company’s name, headline and description, and combines with every other filter.
{ "filters": { "keywords": "(\"data engineer\" OR \"analytics engineer\") AND python NOT intern" } }
SQL
Write aSELECT * FROM companies WHERE ... query in sql. Do not include LIMIT or OFFSET clauses; use the limit and offset parameters instead.
Response Shape
{
"matches": [ { "company": { "..." : "..." } } ],
"total": 3417,
"next_cursor": "k3Vb9xQp2LmZr7Ta..."
}
-
matches: capped at the request’slimit(default 1, max 100). -
total: how many rows match across the whole database, not just this page, so a request withlimit: 1tells you how big a list is (“fintech companies founded after 2018”). TheTotal-Count-Statusheader says how to read it:exact(selective queries),estimate(a broad query’s count ran out of time;totalis a lower bound), orpage(no count;totalis the offset plus the rows returned). Search responses carry nomatch_metadata; only/company/enrichdoes. A broad query returns the same response shape with a lower-bound total, flagged by the header:Total-Count-Status: estimate{ "matches": [ { "company": { "..." : "..." } } ], "total": 62417, "next_cursor": "k3Vb9xQp2LmZr7Ta..." } -
next_cursor: the cursor for the next page when more results follow (send it back ascursor, see Cursors below); null on the last page. -
Industry filters:
industryholds the lowercased LinkedIn industry names in Enums. A filter no stored value can match (an older LinkedIn name such as'%information technology%') returns an empty page at once, free, with aSearch-Warningheader naming the filter and the closest stored values. -
Company name and city aliases: in SQL, a
name_cleanedfilter (=,LIKEorILIKE) also matches the company’s other names:name_cleaned = 'meta'also finds “facebook” and “meta platforms”. Acityorhq_cityfilter also matches the place’s other names:city = 'NYC'also finds “new york”.filtersonname.cleanedand thelocationsplaces match them too, and theSearch-Warningheader names what was also matched.IN (...)lists and query objects (es_query) match without them. -
Case: capitalization never changes the answer: on a direct text column
=,<>,IN,NOT IN,LIKEand~all ignore case, soname = 'Stripe'finds “stripe”. Only a regular expression that asks about case (name_display ~ '^[A-Z]{2,5}$') stays case-sensitive. -
Websites: a domain can be written as a URL:
domain = 'https://www.stripe.com/'means'stripe.com', in SQL and in a query object’stermandterms. -
Field paths: a field can be named as the response writes it.
headline.cleaned,name.displayandlocations.country_codeare read as their columns. -
Short patterns: a one- or two-character contains-pattern matches the whole word on names, industries and descriptions (
'%hp%'finds “hp”, not “hpe” or “shopify”), a whole part of a domain (domain ILIKE '%ai%'finds open.ai and ai.com), and the letters anywhere on places and URLs. TheSearch-Warningheader says which; write the full name, or match the domain’s full value with=. Tickers and exchanges are exempt. -
Sort order: results come in a stable order, with
legion_idas the final tie-break after your ownORDER BY, so the same request returns the same page and paging never repeats or skips a record while the data is unchanged.
Query Objects (es_query)
Instead of SQL, sendes_query: a query object in the Elasticsearch query syntax. It suits code that builds filters, and it uses the field names of the response itself.
{
"es_query": {
"bool": {
"filter": [
{ "terms": { "industry": ["software development", "it services and it consulting"] } },
{ "range": { "legion_employee_count": { "gte": 100 } } },
{ "term": { "locations.country_code": "us" } }
]
}
},
"limit": 25
}
- Supported:
bool(must,should,filter,must_not,minimum_should_match),term,terms,match,match_phrase,range,exists,prefix,wildcardandnested. Anything else, such as scripts, aggregations,regexp,fuzzy,query_stringor boosts, returns a 400; so does a parameter a supported type doesn’t take (such asboostinsideterm). - Fields: the response’s own paths (
domain,industry,locations.city), on fields your contract covers. A trial account searches only the fields its responses include. - Case:
term,terms,prefixandwildcardignore case.matchandmatch_phrasesearch the words of a text field.wildcardtakes*and?, but not at the start of the pattern. locations(offices) is an array: a filter onlocations.*matches when any one office matches, and wrapping several filters innestedmakes them hold for the same office.- Limits: up to 10 levels deep, 100 leaf filters and 1,000 values in one
terms; at most 1,020 conditions once lists are expanded.minimum_should_matchis a count up to 100 or a percentage. - As text: a query object can also be sent as JSON text, which is how a GET request carries one (
?es_query={"term":{"industry":"banking"}}, URL-encoded);filtersworks the same way. Prefer POST: a GET puts the query in the URL. A whole Elasticsearch search body,{"query": {...}}, is read as the query inside it. - Refused: keys other than the documented parameters (such as
aggs,sortorsize) are a 422 that names them, and any query type or parameter not listed above is a 400.
limit, offset and cursor, field selection, credits and the response shape.
Pagination
To page through results beyond the first 100, setoffset to the number of rows to skip. Maximum offset is 10,000.
{
"sql": "SELECT * FROM companies WHERE industry ILIKE '%software%' AND legion_employee_count > 100",
"limit": 100,
"offset": 100
}
Cursors
To read deeper thanoffset allows, or to export a whole result set, page with a cursor. A page with more results after it carries next_cursor; send it back as cursor, without offset, with the same search. On the last page next_cursor is null, even when the page is full.
{
"sql": "SELECT * FROM companies WHERE ...",
"limit": 100,
"cursor": "k3Vb9xQp2LmZr7Ta..."
}
Available Columns
Text Columns
| Column | Description |
|---|---|
name_cleaned | Normalized company name (lowercased). Also written name |
name_display | Display-ready company name (original casing preserved) |
domain | Primary website domain |
industry | Industry, a LinkedIn industry name (see Enums) |
headline_cleaned | LinkedIn headline (lowercased). Also written headline |
description_cleaned | Company description (lowercased). Also written description |
Numeric Columns
| Column | Description |
|---|---|
founded | Year founded |
linkedin_followers | LinkedIn follower count |
linkedin_employee_count | Employee count from LinkedIn |
legion_employee_count | Employee count from Data Legion |
legion_average_tenure | Average employee tenure (months) |
Enum Columns
| Column | Values |
|---|---|
type | private, public, nonprofit, government_agency, educational |
size | 1-10, 11-50, 51-200, 201-500, 501-1000, 1001-5000, 5001-10000, 10001+ |
Workforce Analytics Columns
| Column | Description |
|---|---|
legion_new_hire_count_1m / 3m / 6m / 12m | New hires in the 1/3/6/12 months ending at the as-of month |
legion_attrition_count_1m / 3m / 6m / 12m | Departures in the 1/3/6/12 months ending at the as-of month |
legion_employee_growth_rate_1m / 3m / 6m / 12m | Growth rate as a decimal fraction (0.05 = 5%) |
legion_turnover_rate_1m / 3m / 6m / 12m | Turnover rate as a decimal fraction (0.1 = 10%) |
Location Columns
Filter by where a company has offices. The plain columns match any current office; thehq_ columns match only the headquarters.
| Column | Example | Stored As |
|---|---|---|
city / hq_city | city = 'austin' | Lowercase city name |
state_code / hq_state_code | hq_state_code = 'US-CA' | ISO 3166-2 code with the country prefix |
country_code / hq_country_code | country_code IN ('GB', 'IE') | Two-letter ISO country code |
state / hq_state | state = 'texas' | State or region name in full |
country / hq_country | country = 'united states' | Country name in full |
=, IN (...) and LIKE / ILIKE, ignoring case. A state or country can be written as its code or its name, in any case: state_code = 'CA' or 'California' means 'US-CA', state = 'TX' means 'texas', country = 'US' or 'USA' means 'united states', and country_code = 'usa' means 'US'. A bare state code is read as a US state unless the query names another country. A city name can repeat across countries, so pair it with a country or state when that matters: city = 'london' AND country_code = 'GB'. A company matches when any one of its offices does, so city = 'austin' AND state_code = 'US-TX' can match a company with an office in each. Filtering on locations needs the locations field in your plan.
Cross-Table Columns
These columns search across related tables and are automatically rewritten to subqueries:| Column | Description |
|---|---|
ticker_symbol / ticker | Stock ticker symbol |
exchange | Stock exchange |
social_url | Social media URLs |
alt_domain | Alternative domains |
ILIKE patterns (LIKE matches the same way) with % as the wildcard (ticker ILIKE 'MS%' matches tickers starting with MS), = for an exact match that ignores case (ticker_symbol = 'aapl', alt_domain = 'google.com') and IN (...) for any of several values. To exclude, wrap the filter: NOT (exchange = 'nasdaq'). Other operators on these columns, such as ~*, NOT ILIKE or NOT IN (...), return a 400 that lists the supported forms.
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%'
-- Software companies headquartered in Austin
SELECT * FROM companies WHERE industry = 'software development' AND hq_city = 'austin' AND hq_state_code = 'US-TX'
-- Fast-growing companies (20%+ growth over the 6 months to the as-of month)
SELECT * FROM companies WHERE legion_employee_growth_rate_6m > 0.2
-- Companies with high turnover (30%+ over the 12 months to the as-of month)
SELECT * FROM companies WHERE legion_turnover_rate_12m > 0.3 AND legion_employee_count > 50
Body
Request model for Company Search: sql, es_query or filters, and the page.
Continue a search from the previous page's next_cursor: the next page in the same order, past offset's 10,000-row reach, for deep pages and exports. Send the same query, and no offset. A cursor works for the dataset build it came from; after a new build, start again.
65536Response
Success - query executed and results returned
Company Search response: a page of matches.
For /company/search and /company/discover, the total number of rows matching the query's WHERE clause across the database (not just this page). On search/discover, if the exact count exceeds its time budget (broad, low-selectivity queries) it falls back to the matches counted before the budget ran out (a lower bound), and if that does not cover this page, to the offset plus the rows returned; the response header Total-Count-Status reports which (exact, estimate, or page).