Choosing fields

Every read in the API takes fields: the fields of each record you want back, and nothing else. Ask for a contest’s title and its candidates’ names and you get just those, instead of the district, the election, the result and every endorser. Responses get smaller and faster to read, for your code and for an AI assistant reading them through the MCP server.

An example

The contests on California’s November ballot, with only each contest’s id and title and each choice’s label, whether it is the incumbent, and how many endorsers back it:

GET /v1/contests with fields
curl -G "https://api.ballotdata.ai/v1/contests" \
  --data-urlencode "elections=ca-2026-11-03-general" \
  --data-urlencode "fields=id,title,choices(label,incumbent,endorsement_count)" \
  -H "Authorization: Bearer $BALLOTDATA_API_KEY"
{
  "data": [
    {
      "id": 4410,
      "title": "Member, Board of Supervisors, District 8",
      "choices": [
        {
          "label": "Jane Doe",
          "incumbent": true,
          "endorsement_count": 14
        },
        {
          "label": "Sam Rivera",
          "incumbent": false,
          "endorsement_count": 9
        }
      ]
    },
    {
      "id": 4502,
      "title": "Proposition K: Affordable Housing Bond",
      "choices": [
        {
          "label": "Yes",
          "incumbent": null,
          "endorsement_count": 31
        },
        {
          "label": "No",
          "incumbent": null,
          "endorsement_count": 4
        }
      ]
    }
  ],
  "next_cursor": "aTo0NTAy"
}

Without fields you get every field, as before: nothing changes for code that doesn’t use it.

How to write it

fields is a comma-separated list of field names, the same names as in the API reference and the data dictionaries.

You writeYou get
id,titleThose two fields of each record.
district.nameA dot reaches into a nested object: { "district": { "name": … } }.
choices.labelThrough a list, the dot applies to every item: each choice keeps only its label.
choices(label,party)Parentheses group several fields under one. The same as choices.label,choices.party.
elections(election.slug,contests(title,choices.label))Groups nest, and dots work inside them.
districtA field named alone comes back whole, with everything nested in it.

Names are letters, digits and underscores; spaces around them are ignored. Remember to URL-encode the value (curl’s --data-urlencode and the client libraries do it for you), though commas, dots and parentheses are safe in a URL as they are.

What to expect

  • Only the records are cut down. In a list, each record in data is; for one record, data itself is. next_cursor, has_more and the rate-limit headers always come back, so paging works exactly as without fields.
  • The record’s own order. Fields come back in the order the API always gives them, not the order you listed them.
  • Nothing is invented. A field that is null stays null (asking for result.status on a contest without a result gives "result": null), and a field a record doesn’t have, such as an optional one, is left out rather than added.
  • Filters still apply first. fields chooses what each record shows, not which records come back: use the filter parameters for that. limit still counts records.
  • One request. A request with fields counts against your limits as one request, like any other.
  • Limits. Up to 200 paths, 8 levels deep and 2,000 characters.
  • Free-form objects. A few fields hold a map whose keys depend on the data, such as outcomes on GET /v1/seat-changes. Any key is accepted inside those.

Mistakes are errors, not empty answers

Every path is checked against the endpoint’s response schema before anything is read. A misspelled or unknown field, a path into a plain value (title.text), unbalanced parentheses or an empty fields= is a 400 with the code invalid_parameter, and the message names the fields that do exist at that point:

{
  "error": {
    "code": "invalid_parameter",
    "message": "fields: \"choices.lable\" isn't a field here. choices has: id, label, measure_answer, …",
    "request_id": "8c1f2a4e-6b7d-4c3e-9f10-2a3b4c5d6e7f"
  }
}

The stream (GET /v1/stream) and the requests that change subscriptions don’t take fields; sending it there is a 400 too.

With CSV

On the lists and endorser studies that answer format=csv, the same fields picks the columns: a column stays when the JSON field it is copied from was asked for (each data dictionary names that field beside every column). So fields=id,title,choices.label&format=csv on GET /v1/contests gives the columns contest_id,contest_title,choice_label, and one fields value works in both formats. Rows are still one per record, or one per choice where the CSV is laid out that way. Fields that no column comes from, such as details, are a 400 if nothing else is asked for.

The election export’s CSV (GET /v1/elections/{slug}/export?format=csv) is one row per endorsement with its own columns, so there fields takes the column names themselves, such as fields=contest_title,choice_label,endorser_name. Its JSON takes field paths like everywhere else.

In the client libraries

Both client libraries pass fields through on every method, as a string or as a list of paths. The libraries’ types still describe whole records, so treat a field you didn’t ask for as missing.

fields in every request
# fields is a query parameter on every read
curl -G "https://api.ballotdata.ai/v1/states" --data-urlencode "fields=code,name" \
  -H "Authorization: Bearer $BALLOTDATA_API_KEY"

# POST /v1/ballot too: fields goes in the query string, the address in the body
curl -X POST "https://api.ballotdata.ai/v1/ballot?fields=elections(election.slug,contests(title,choices.label))" \
  -H "Authorization: Bearer $BALLOTDATA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"address": "1 Dr Carlton B Goodlett Pl, San Francisco, CA 94102"}'

# A list of paths is the same paths joined with commas
curl -G "https://api.ballotdata.ai/v1/endorsements" --data-urlencode "states=CA" \
  --data-urlencode "fields=endorser.name,choice.label" \
  -H "Authorization: Bearer $BALLOTDATA_API_KEY"

For AI assistants (MCP)

Every tool on the BallotData MCP server that reads data takes the same fields argument, described in each tool’s input schema, so an assistant can ask for only what it needs and keep its context small. For example, a list_contests call:

{
  "name": "list_contests",
  "arguments": {
    "elections": ["ca-2026-11-03-general"],
    "fields": "id,title,choices(label,incumbent,endorsement_count)"
  }
}

Assistants can learn the field names from the describe_record tool or the records’ data dictionaries, and an unknown name comes back as an error listing the names that exist, which an assistant can correct and retry. Leave fields out when you don’t know yet what you need: the full record is always the default.

Every endpoint, with an example

Each of these takes fields. The example is the one shown in the reference.

EndpointExample
GET /v1/statesfields=code,name
GET /v1/electionsfields=slug,name,date,state
GET /v1/coveragefields=state,contest_count,endorsement_count
GET /v1/elections/{slug}/exportfields=election.slug,contests(title,choices.label)
GET /v1/searchfields=type,slug,label,path
POST /v1/ballotfields=districts.name,elections(election.slug,contests(title,choices.label))
GET /v1/contestsfields=id,title,district.name,choices(label,party)
GET /v1/contests/{id}fields=id,title,choices.label,endorsements(endorser.name,picks.label)
GET /v1/measure-topicsfields=slug,name
GET /v1/resultsfields=title,status,winners,choices(label,votes,vote_pct)
GET /v1/endorser-categoriesfields=slug,name
GET /v1/endorsersfields=slug,name,category.name,state
GET /v1/endorsers/{slug}fields=slug,name,category.name,website_url,endorsement_count
GET /v1/endorsers/{slug}/recordfields=endorser.name,totals
GET /v1/endorsers/{slug}/agreementfields=endorser.slug,compared(endorser.name,agreement_rate)
GET /v1/endorsementsfields=id,endorser.name,contest.title,choice.label
GET /v1/endorsements/{id}fields=id,statement,source_url,endorser.name,choice.label
GET /v1/endorsements/{id}/historyfields=at,change,changed
GET /v1/changesfields=at,change,endorsement_id,endorser.slug
GET /v1/candidatesfields=id,full_name,contests.contest.title
GET /v1/candidates/{id}fields=full_name,website_url,contests(contest.title,endorsement_count),issue_positions(issue,stance)
GET /v1/issuesfields=slug,question
GET /v1/issue-positionsfields=issue,stance,summary,candidate.full_name
GET /v1/committee-contributionsfields=amount,date,committee.name,candidate.full_name
GET /v1/officeholdersfields=name,office_title,party,email
GET /v1/officeholders/{id}fields=name,office_title,party,phone,website_url
GET /v1/officesfields=slug,name,current_holders.name
GET /v1/offices/{slug}fields=slug,name,terms(name,party,start_date,end_date)
GET /v1/office-termsfields=name,party,start_date,end_date
GET /v1/seat-changesfields=totals,groups.group
GET /v1/eventsfields=id,type,occurred_at,endorser.slug,choice.label
GET /v1/subscriptionsfields=id,name
GET /v1/subscriptions/{id}fields=id,name
Choosing fields · BallotData API