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

# Run a search, then enrich with a function

> Use Searches to find records, then run Clay-managed functions on the results.

This is the simplest high-value Clay developer flow:

1. Use Searches to find companies or people.
2. Pass the results into a routine.
3. Use Clay-managed functions to enrich the records.

For example, you might search for heads of sales at B2B SaaS companies, then run a Clay-managed function to find work emails.

## 1. Run a search

Fetch the query reference, write a query, create a search, then fetch the first page of results.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request GET \
  --url https://api.clay.com/public/v0/search/query-mode/reference \
  --header "clay-api-key: $CLAY_PUBLIC_API_KEY"

QUERY='select from people where experiences.any('\
'is_current = true and '\
'job_title is_similar_to ("VP Sales", "Head of Sales") and '\
'company.estimated_employee_count >= 500 and '\
'company.industry = "Software Development")'

SEARCH_ID=$(curl --request POST \
  --url https://api.clay.com/public/v0/search/query-mode \
  --header "Content-Type: application/json" \
  --header "clay-api-key: $CLAY_PUBLIC_API_KEY" \
  --data "$(jq -n --arg query "$QUERY" '{query: $query}')" \
  | jq -r '.search_id')

curl --request POST \
  --url "https://api.clay.com/public/v0/search/query-mode/$SEARCH_ID/run" \
  --header "Content-Type: application/json" \
  --header "clay-api-key: $CLAY_PUBLIC_API_KEY" \
  --data '{ "limit": 10 }'
```

## 2. Choose a function

Use a Clay-managed function when Clay already provides the enrichment you need, such as finding emails, phone numbers, company data, technology data, funding, or job openings.

<Card title="Clay-managed functions" href="/routines/clay-managed-functions">
  Learn when to use Clay-provided functions.
</Card>

## 3. Run the function

Run the function routine on the records you want to enrich.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
echo '{"items":[{"id":"person-1","inputs":{"domain":"example.com","full_name":"Ada Lovelace"}}]}' \
  | clay routines runs start function:t_abc123 --input -
```

Then fetch the result:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
clay routines runs get run_abc123
```

## Next steps

<Card title="Searches" href="/searches">
  Learn the search flow in more detail.
</Card>

<Card title="Batch runs" href="/routines/batch-runs">
  Run the same routine across many records.
</Card>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.