Service endpoint

https://api.targetsmart.com/service/district

Overview

Retrieve political district data using one of several lookup options. A request can specify an address, geo-location, or zip code. The JSON response returns the corresponding political geography and district information. The request is executed synchronously with low latency.

Request parameters

This service supports three search modes, zip, point, and address. The service must be specified in search_type.

Key Required Optional Default Permitted Values
search_type zip zip, point, address

ZIP9 Search (default)

This is the default search_type, and that key can be omitted. Both a 5-digit zip code (zip5) and the +4 portion (zip4) are required.

Key Required Optional Default Permitted Values
zip5 5 integers
zip4 4 integers
state Two character U.S. state code (e.g. NY)

If search_type is point, these fields are available.

Key Required Optional Default Permitted Values
latitude Floating point number (e.g. 33.738987255507)
longitude Floating point number (e.g. -116.40833849559)
state Two character U.S. state code (e.g. NY)

If search_type is address, these fields are available.

Key Required Optional Default Permitted Values
address Any geocode-able address
state Two character U.S. state code (e.g. NY)

In the address field, when employing either the point or address search modes, it is beneficial to add state and zip code details if this information is accessible. This practice enhances the accuracy of the matching results.

Though including the state parameter is not mandatory, its utilization is advised whenever the data is obtainable. This parameter aids in refining geospatial search outcomes, thereby yielding more precise results.

Additional parameter details

search_type

Acceptable values:

  • zip - Search using ZIP and ZIP+5
  • point - Search using latitude and longitude
  • address - Search using geocodable address

JSON response

Search responses are JSON objects with the following keys:

  • match_found: true/false indicating if a matching record was found
  • match_data: matching district data (see below)

The match_data attribute is a nested JSON object with the following keys:

Attribute Description
vb.vf_reg_cass_state State Abbreviation
vb.vf_reg_cass_zip ZIP code
vb.vf_reg_cass_zip4 ZIP+4 code
vb.vf_precinct_id Precinct Id
vb.vf_precinct_name Precinct Name
vb.vf_township Township Name
vb.vf_ward Ward Name
vb.vf_county_name County Name
vb.vf_sd State Senate District
vb.vf_hd State House District
vb.vf_cd Congressional District
vb.vf_city_council City Council District
vb.vf_municipal_district Municipal District
vb.vf_county_council County Council District
vb.vf_judicial_district Judicial District
vb.vf_school_district School District

Code Examples

🔐 Remember to secure your API key

Never expose your API key in plain text or source control accessible by a third party.

#! /usr/bin/env python3

import os
import requests

api_key = os.environ["TS_API_KEY"]

# `point` query
response = requests.get(
    "https://api.targetsmart.com/service/district",
    params={"search_type": "point", "latitude": 40.2971079, "longitude": -83.2112569},
    headers={"x-api-key": api_key},
)
response.raise_for_status()
print(response.json())

# `zip` query
response = requests.get(
    "https://api.targetsmart.com/service/district",
    params={"search_type": "zip", "zip5": "33410", "zip4": "4776"},
    headers={"x-api-key": api_key},
)
response.raise_for_status()
print(response.json())

# `address` query
response = requests.get(
    "https://api.targetsmart.com/service/district",
    params={
        "search_type": "address",
        "address": "1155 15th St NW #750, Washington, DC",
    },
    headers={"x-api-key": api_key},
)
response.raise_for_status()
print(response.json())
#! /usr/bin/env node

const fetch = require("node-fetch");

const targetSmartApiKey = process.env.TS_API_KEY;

// `point` query
fetch(
  "https://api.targetsmart.com/service/district?" +
    new URLSearchParams({
      search_type: "point",
      latitude: 40.2971079,
      longitude: -83.2112569,
    }).toString(),
  {
    method: "GET",
    headers: {
      "x-api-key": targetSmartApiKey,
    },
  }
)
  .then((res) => res.json())
  .then((json) => console.log(json));

// `zip` query
fetch(
  "https://api.targetsmart.com/service/district?" +
    new URLSearchParams({
      search_type: "zip",
      zip5: "33410",
      zip4: "4776",
    }).toString(),
  {
    method: "GET",
    headers: {
      "x-api-key": targetSmartApiKey,
    },
  }
)
  .then((res) => res.json())
  .then((json) => console.log(json));

// `address` query
fetch(
  "https://api.targetsmart.com/service/district?" +
    new URLSearchParams({
      search_type: "address",
      address: "1155 15th St NW #750, Washington, DC",
    }).toString(),
  {
    method: "GET",
    headers: {
      "x-api-key": targetSmartApiKey,
    },
  }
)
  .then((res) => res.json())
  .then((json) => console.log(json));
#! /usr/bin/env bash

# `point` query
result=$(curl -XGET \
    -H "x-api-key: $TS_API_KEY" \
    "https://api.targetsmart.com/service/district?search_type=point&latitude=40.2971079&longitude=-83.2112569")
echo $result

# `zip` query
result=$(curl -XGET \
    -H "x-api-key: $TS_API_KEY" \
    "https://api.targetsmart.com/service/district?search_type=zip&zip5=33410&zip4=4776")
echo $result

# `address` query
result=$(curl -XGET \
    -H "x-api-key: $TS_API_KEY" \
    "https://api.targetsmart.com/service/district?search_type=address&address=1155%2015th%20St%20NW%20%23750%2C%20Washington%2C%20DC")
echo $result