Count persons a search would match
curl --request POST \
--url https://api.datalegion.ai/person/search/count \
--header 'API-Key: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"query": "SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'"
}
EOFimport requests
url = "https://api.datalegion.ai/person/search/count"
payload = { "query": "SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'" }
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({
query: 'SELECT * FROM people WHERE job_title = \'nurse\' AND state_code = \'US-TX\''
})
};
fetch('https://api.datalegion.ai/person/search/count', 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/person/search/count",
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([
'query' => 'SELECT * FROM people WHERE job_title = \'nurse\' AND state_code = \'US-TX\''
]),
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/person/search/count"
payload := strings.NewReader("{\n \"query\": \"SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'\"\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/person/search/count")
.header("API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalegion.ai/person/search/count")
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 \"query\": \"SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'\"\n}"
response = http.request(request)
puts response.read_body{
"total": 123,
"total_status": "about",
"generated_query": {}
}{
"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": {}
}Person
Person Search Count API
Count the people a person search would match, free and without returning records, to size a list before you buy it.
POST
/
person
/
search
/
count
Count persons a search would match
curl --request POST \
--url https://api.datalegion.ai/person/search/count \
--header 'API-Key: <api-key>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"query": "SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'"
}
EOFimport requests
url = "https://api.datalegion.ai/person/search/count"
payload = { "query": "SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'" }
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({
query: 'SELECT * FROM people WHERE job_title = \'nurse\' AND state_code = \'US-TX\''
})
};
fetch('https://api.datalegion.ai/person/search/count', 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/person/search/count",
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([
'query' => 'SELECT * FROM people WHERE job_title = \'nurse\' AND state_code = \'US-TX\''
]),
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/person/search/count"
payload := strings.NewReader("{\n \"query\": \"SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'\"\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/person/search/count")
.header("API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalegion.ai/person/search/count")
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 \"query\": \"SELECT * FROM people WHERE job_title = 'nurse' AND state_code = 'US-TX'\"\n}"
response = http.request(request)
puts response.read_body{
"total": 123,
"total_status": "about",
"generated_query": {}
}{
"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": {}
}Send what Person Search takes (
A count is rounded, so adding or removing one record almost never changes it. For an exact total, run the search itself: its
filters, sql or es_query) and get back how many people it matches, rounded, without any records. A count costs no credits, so you can size a list and work out what it would cost (one credit per record returned) before you search.
{ "filters": { "job_title": "nurse practitioner", "state_code": "TX" } }
{ "total": 1200, "total_status": "about" }
Reading the Total
total is rounded, and total_status (also the Total-Count-Status response header) says how to read it:
| total_status | Meaning | Say it as |
|---|---|---|
about | The count, rounded: to the nearest 10 under 100, else to two significant figures | ”about 1,200” |
at_least | Counting ran out of time on a very broad search; total is a lower bound | ”1,200 or more” |
under | Fewer than 10 match, possibly none | ”fewer than 10” |
total is exact for selective queries.
A count describes a list, not one record: it refuses (400, free) filters on fields that identify a single person: legion_id, names, emails, phones, social and LinkedIn URLs, NPI. Whether a field is filled is fine, for example “nurse practitioners in Texas with a work email”: "work_email": {"exists": true}; only a specific value is refused. To look one up, use Person Enrichment.
Sent as filters, the response also carries generated_query, the query object the filters compiled to.
Limits
- Free: no credits are used.
- Works with zero credits left: a count needs an active plan that includes search (a trial counts too), not a balance, so you can size a list before you buy more. An expired plan answers 402; a plan without search, 403.
- 10 counts a minute and 100 an hour per account (5 and 30 on a free trial), for each of person and company. Higher limits are available on request.
- The same field rules as search: a filter on a field outside your plan is refused, and opted-out records are never counted.
- GET works too, with
filters,sqlores_queryas query parameters (filtersandes_queryas JSON text). Prefer POST.
Body
application/json
Request model for a person search's count: the query or filters alone, no records.
Response
Success - the rounded count of matching persons
How many records a search would match, rounded.