---
title: Texas Comptroller (United States)
url: https://documentation.cluedin.net/govern/rest-api-enricher-samples/comptroller-texas
content_type: reference
section: Govern & improve > REST API enricher samples
---

# Texas Comptroller (United States)

> reference: Facts, options, APIs.

This example looks up an organization's 11-digit Texas taxpayer number in the list of active franchise taxpayers that the Texas Comptroller of Public Accounts publishes on the [Texas Open Data Portal](https://data.texas.gov/) (dataset `9cir-efmm`, *Active Franchise Taxpayers*). For each golden record it stores the taxpayer name and address, the organization type, the Texas Secretary of State file number, charter date and status, whether the taxpayer has the right to transact business in Texas, any franchise tax exemption, and the NAICS code. No API key is needed.

**Enricher version:** V2  
**API key:** not needed (an optional data.texas.gov app token raises the rate limit)

### The Comptroller's register, not the Secretary of State's

The Texas Secretary of State keeps the register of business entities, but it has no public API; its SOSDirect search is a paid web service. This sample uses the Comptroller's franchise tax register instead. It covers taxpayers with an active franchise tax account: Texas corporations, LLCs, partnerships and other taxable entities, and out-of-state entities registered to do business in Texas. Where the taxpayer is registered with the Secretary of State, the row includes its Secretary of State file number (`texas.sosFileNumber`), charter date and status, as the Comptroller holds them.

The Comptroller also has a [Public Data API](https://api-doc.comptroller.texas.gov/) with a franchise tax endpoint (`GET https://api.comptroller.texas.gov/public-data/v1/public/franchise-tax/{taxpayerId}`, free API key in the `x-api-key` header). According to its specification it also returns the FEIN, DBA name, state of formation, registered agent and office, and officers. It needs an API key, so this sample doesn't use it. If you have a key, you can adapt the script to call it.

To set up the enricher, see [Add REST API enricher](https://documentation.cluedin.net/govern/enrichment/rest-api.md#add-rest-api-enricher), then use the settings and script on this page.

## Settings

- **Accepted Business Domain** – `/Organization`, or the business domain that holds your companies.

- **Version** – V2 (recommended).

- **API Key** – leave empty, or enter a data.texas.gov app token. Without a token, data.texas.gov limits how many requests it accepts from one address; with one, the limit is much higher. To get a token, sign in to [data.texas.gov](https://data.texas.gov/) and create an app token in your developer settings (see [Socrata app tokens](https://dev.socrata.com/docs/app-tokens.html)). The script sends it in the `X-App-Token` header.

- **Filters** – we recommend a rule that only accepts golden records where `organization.texasTaxpayerNumber` has a value. Otherwise, every record without a taxpayer number is listed on the enricher's **Logs** tab as having returned no results.

## Vocabulary and Properties

```
organization.texasTaxpayerNumber
```

`organization.texasTaxpayerNumber` holds the 11-digit Texas taxpayer number (Texas taxpayer ID) that the Comptroller assigns. If your data uses another vocabulary key, change this field and the `TAXPAYER_NUMBER_KEY` value at the top of the script.

## Request and response

**Base URL:** `https://data.texas.gov/resource`  
**Endpoint:** `GET /9cir-efmm.json?$where=starts_with(taxpayer_number,'{taxpayerNumber}')`  
**Authentication:** none; optional app token in the `X-App-Token` header  
**Rate limits:** requests without an app token are throttled per IP address; see [Socrata app tokens](https://dev.socrata.com/docs/app-tokens.html). Each request takes about 1–2 seconds.

The script sends one request per golden record. It uses `starts_with` rather than `taxpayer_number={taxpayerNumber}` because a few hundred rows have the number padded with a trailing space, which an exact match misses:

```http
GET https://data.texas.gov/resource/9cir-efmm.json?$where=starts_with(taxpayer_number,'17424878340')
Accept: application/json
```

Response (one row for each franchise tax registration with the number; real response for Dell Inc.):

```json
[
  {
    "taxpayer_number": "17424878340",
    "taxpayer_name": "DELL INC.",
    "taxpayer_address": "ONE DELL WAY RR1-35 TAX DEPT",
    "taxpayer_city": "AUSTIN",
    "taxpayer_state": "TX",
    "taxpayer_zip": "78714",
    "taxpayer_county_code": "227",
    "taxpayer_organizational_type": "CF",
    "record_type_code": "V",
    "responsibility_beginning_date": "1987-10-27T00:00:00.000",
    "secretary_of_state_sos_or_coa_file_number": "0007444706",
    "sos_charter_date": "1987-10-27T00:00:00.000",
    "sos_status_date": "1987-10-27T00:00:00.000",
    "sos_status_code": "A",
    "right_to_transact_business_code": "A",
    "_621111": "551112"
  }
]
```

An empty array (`[]`) means that the number isn't in the list of active franchise taxpayers. The code values are explained in the record layout attached to the dataset (*Franchise Layout.docx*); the script turns the organization type, record type, Secretary of State status and right to transact business codes into their descriptions.

## Properties added by the enricher

| Property | Response field | Example |
| -------- | -------------- | ------- |
| `texas.taxpayerNumber` | `taxpayer_number` | `17424878340` |
| `texas.name` | `taxpayer_name` | `DELL INC.` |
| `texas.address` | `taxpayer_address` | `ONE DELL WAY RR1-35 TAX DEPT` |
| `texas.city` | `taxpayer_city` | `AUSTIN` |
| `texas.state` | `taxpayer_state` | `TX` |
| `texas.zipCode` | `taxpayer_zip` | `78714` |
| `texas.countyCode` | `taxpayer_county_code`; `0` for addresses outside Texas | `227` |
| `texas.organizationType` | description of `taxpayer_organizational_type` | `FOREIGN PROFIT CORPORATION` |
| `texas.organizationTypeCode` | `taxpayer_organizational_type` | `CF` |
| `texas.sosFileNumber` | `secretary_of_state_sos_or_coa_file_number` | `0007444706` |
| `texas.sosFileNumberType` | description of `record_type_code`: `SOS file number` (Texas entity) or `SOS certificate of authority (COA) file number` (out-of-state entity) | `SOS certificate of authority (COA) file number` |
| `texas.sosCharterDate` | `sos_charter_date`, as `YYYY-MM-DD` | `1987-10-27` |
| `texas.sosStatus` | description of `sos_status_code`, for example `Active`, `Reinstated` or `Forfeited Franchise Tax` | `Active` |
| `texas.sosStatusCode` | `sos_status_code` | `A` |
| `texas.sosStatusDate` | `sos_status_date`, as `YYYY-MM-DD` | `1987-10-27` |
| `texas.rightToTransactBusiness` | description of `right_to_transact_business_code`: `Active`, `Active - Eligible for Termination/Withdrawal`, `Forfeited`, `Franchise Tax Involuntarily Ended` or `Franchise Tax Not Established` | `Active` |
| `texas.responsibilityBeginDate` | `responsibility_beginning_date` (date the taxpayer became liable for franchise tax), as `YYYY-MM-DD` | `1987-10-27` |
| `texas.exemptReasonCode` | `current_exempt_reason_code` (franchise tax exemption reason; see the record layout) | `23` |
| `texas.exemptBeginDate` | `exempt_begin_date`, as `YYYY-MM-DD` | `1985-01-07` |
| `texas.naicsCode` | `_621111` (NAICS code) | `551112` |

A property is added only when the dataset has a value for it. Taxpayers with a Comptroller-assigned number (`record_type_code` `X`) have no Secretary of State file number, charter date or status. An unknown code is kept in the `...Code` property without a description.

If the enricher has a **Preview** tab, the results appear there first. To add them to golden records, go to the **Map** tab, select **Map Data**, and choose **Auto Mapping**. Select the business domain, enter a new vocabulary named `Texas Comptroller` with the key prefix `texas`, and then create the mapping. Auto mapping also uses `name` as the golden record name, so remove that from the mapping if you want to keep your existing names. Then process the data on the **Process** tab. If the enricher has no **Preview** tab, the properties are added to the golden record as soon as it is enriched.

## How the script handles input and errors

- Spaces, dots, dashes and slashes are removed, so `1-74-2487834-0` is looked up as `17424878340`. The number must then have exactly 11 digits and not be all zeros. The Comptroller doesn't publish a check digit algorithm, so no check digit is verified. Golden records without a valid number are skipped without calling the API.

- Values are trimmed; some rows have values padded with spaces.

- A few taxpayers have more than one row, for example an old and a new Secretary of State registration. The script uses this order to choose one:
  1. A row with an active right to transact business (`A` or `D`) comes before one without.
  2. An active or reinstated Secretary of State status (`A` or `R`) comes before another status.
  3. The row with the latest Secretary of State status date (or charter date) comes first.

- If the number isn't in the list, the request is rejected, or the API returns an error, the script logs the reason and adds nothing, and nothing is cached.

- If you entered an app token and data.texas.gov rejects it, the script throws an error that says so, and the golden record fails.

- If data.texas.gov limits the requests (HTTP 429), the script throws an error that makes the enricher try the golden record again later. Enter an app token if this happens often.

- Successful results are cached for 24 hours per taxpayer number. To change this, edit `CACHE_MILLISECONDS` in the script.

## Testing the enricher

- **Test connection** checks only that the script runs. It doesn't call the API.

- To try the setup, create a golden record with `organization.texasTaxpayerNumber` set to `17424878340` (Dell Inc.) or `17430106579` (H-E-B, LP).

## Limitations

- Only taxpayers with an active franchise tax account are listed. Entities whose franchise tax account has ended, and entities that don't owe franchise tax (such as sole proprietorships and general partnerships owned by individuals), get no result.

- The dataset is a periodic extract that the Comptroller updates about once a month, not a live query.

- The address is the taxpayer's mailing address for franchise tax, not necessarily its registered office. Registered agents and officers aren't in the dataset (they are in the Comptroller's Public Data API, which needs an API key).

- Lookups by name or by Secretary of State file number aren't supported. To look up by file number, change the `$where` filter to use `secretary_of_state_sos_or_coa_file_number`.

- Values are in capital letters, as they are in the dataset. Exemption reason codes aren't turned into descriptions.

## Process script

```javascript
// REST API enricher (V2) - Texas franchise taxpayer lookup at the Texas Comptroller of Public Accounts
//
// Looks up a golden record's 11-digit Texas taxpayer number in the Comptroller of Public Accounts'
// list of active franchise taxpayers, published on the Texas Open Data Portal
// (https://data.texas.gov/, dataset 9cir-efmm, "Active Franchise Taxpayers"), and adds the result
// to the golden record as texas.* properties:
//
//   texas.taxpayerNumber          taxpayer number that was looked up
//   texas.name                    taxpayer name
//   texas.address                 taxpayer (mailing) address
//   texas.city                    city of that address
//   texas.state                   state of that address
//   texas.zipCode                 ZIP code of that address
//   texas.countyCode              Comptroller county code (0 for addresses outside Texas)
//   texas.organizationType        organization type, for example TEXAS LIMITED LIABILITY COMPANY
//   texas.organizationTypeCode    organization type code, for example CL
//   texas.sosFileNumber           Texas Secretary of State file number or certificate of authority number
//   texas.sosFileNumberType       SOS file number (Texas entity) or COA file number (foreign entity)
//   texas.sosCharterDate          date the Secretary of State chartered or registered the entity (YYYY-MM-DD)
//   texas.sosStatus               Secretary of State status, for example Active or Forfeited Franchise Tax
//   texas.sosStatusCode           Secretary of State status code, for example A
//   texas.sosStatusDate           date of that status (YYYY-MM-DD)
//   texas.rightToTransactBusiness right to transact business in Texas, for example Active or Forfeited
//   texas.responsibilityBeginDate date the taxpayer became liable for franchise tax (YYYY-MM-DD)
//   texas.exemptReasonCode        franchise tax exemption reason code, when the taxpayer is exempt
//   texas.exemptBeginDate         date the exemption began (YYYY-MM-DD)
//   texas.naicsCode               NAICS industry code
//
// This is the Comptroller's franchise tax register, not the Secretary of State's business
// register (the Secretary of State has no public API). It lists taxpayers with an active
// franchise tax account, including foreign entities registered to do business in Texas.
//
// No API key is needed. An optional Socrata app token (for higher rate limits) can be entered
// in the API Key field. See README.md next to this file for the enricher settings.
//
// A record gets no result (nothing is stored) when it has no valid taxpayer number, when the
// number isn't in the list, or when the API can't answer.

// ---- Settings -------------------------------------------------------------------------

// Vocabulary key to read. Add the same key to the Vocabulary and Properties field.
const TAXPAYER_NUMBER_KEY = "organization.texasTaxpayerNumber";

// The enricher replaces {APIKey} with the API Key field value: an optional data.texas.gov
// (Socrata) app token. Leave the field empty to call the API without one.
const APP_TOKEN = "{APIKey}";

const TEXAS_URL = "https://data.texas.gov/resource/9cir-efmm.json";

// How long to reuse an answer for the same taxpayer number. 0 turns caching off.
const CACHE_MILLISECONDS = 24 * 60 * 60 * 1000;

// ---- Script ---------------------------------------------------------------------------

// Code values from the Comptroller's record layout for this dataset ("Franchise Layout.docx").
const ORGANIZATION_TYPES = {
  AB: "TEXAS BUSINESS ASSOC", AC: "FRGN BUSINESS ASSOC", AF: "FOREIGN PROFESSIONAL ASSOCIATION",
  AP: "TEXAS PROFESSIONAL ASSOCIATION", AR: "OTHER ASSOCIATION", C: "CORPORATION",
  CF: "FOREIGN PROFIT CORPORATION", CI: "FOREIGN LMTD LIAB CO - OOS", CL: "TEXAS LIMITED LIABILITY COMPANY",
  CM: "FOREIGN NON-PROFIT CORP - OOS", CN: "TEXAS NON-PROFIT CORPORATION", CP: "TEXAS PROFESSIONAL CORPORATION",
  CR: "TEXAS INSURANCE CORPORATION", CS: "FOREIGN INSURANCE CORP - OOS", CT: "TEXAS PROFIT CORPORATION",
  CU: "FOREIGN PROFESSIONAL CORPORATION", CW: "TEXAS RAILROAD CORPORATION", CX: "FOREIGN RAILROAD CORPORATION",
  DC: "REGISTERED DATA CENTER", ES: "ESTATE", FP: "FINANCIAL INSTITUTION", HF: "FRGN HOLDING COMPANY",
  HS: "HISTORIC STRUCTURE", IS: "INDIVIDUAL - SOLE OWNER", J: "JOINT VENTURE", L: "LIMITED (LIABILITY) COMPANY",
  M: "LIMITED (LIABILITY) PARTNERSHIP", O: "OTHER", P: "GENERAL PARTNERSHIP", PB: "BUS GENERAL PRTNSHP",
  PF: "FRGN LIMITED PRTNSHP", PI: "IND GENERAL PRTNSHP", PL: "TX LIMITED PRTNSHP", PO: "OIL & GAS SPECIAL",
  PV: "TEXAS JOINT VENTURE", PW: "FRGN JOINT VENTURE", PX: "TX LLP REGISTRATION", PY: "FRGN LLP REGISTRATION",
  PZ: "IND SUCCESSOR PRTSHP", S: "SOLE PROPRIETORSHIP", SF: "FRGN JOINT STOCK CO", ST: "TEXAS JOINT STOCK CO",
  TF: "FOREIGN BUSINESS TRUST", TH: "TX RL EST INV TRST", TI: "FOREIGN REAL ESTATE INVESTMENT TRUST",
  TR: "TRUST", UF: "UNKNOWN - FRANCHISE", UK: "UNKNOWN",
};

const SOS_FILE_NUMBER_TYPES = {
  U: "SOS file number",
  V: "SOS certificate of authority (COA) file number",
};

const SOS_STATUSES = {
  A: "Active", B: "Consolidated", C: "Converted", D: "Dissolved", E: "Expired",
  F: "Forfeited Franchise Tax", G: "Miscellaneous", I: "Closed by FDIC", J: "State Charter Pulled",
  K: "Forfeited Registered Agent", L: "Forfeited Registered Office", M: "Merger", N: "Forfeited Hot Check",
  P: "Forfeited Court Order", R: "Reinstated", T: "Terminated", W: "Withdrawn",
  Y: "Dead at Conversion 69", Z: "Dead at Conversion 83",
};

const RIGHT_TO_TRANSACT_BUSINESS = {
  A: "Active",
  D: "Active - Eligible for Termination/Withdrawal",
  N: "Forfeited",
  I: "Franchise Tax Involuntarily Ended",
  U: "Franchise Tax Not Established",
};

function getValue(key) {
  // A plain loop rather than vocabularies.find(...): vocabularies is a .NET list, and when
  // .find is called from inside a function, later calls return the first call's match.
  const items = vocabularies || [];
  for (let i = 0; i < items.length; i++) {
    if (items[i].Key === key) {
      const value = items[i].Value;
      return value === null || value === undefined ? "" : String(value).trim();
    }
  }
  return "";
}

// Accepts "17424878340", "1-74-2487834-0", "174 2487 8340", etc. Returns the 11 digits or null.
// The Comptroller doesn't publish a check digit algorithm, so only the length is checked.
function parseTaxpayerNumber(raw) {
  const text = raw.replace(/[\s.\-\/]/g, "");
  if (!/^\d{11}$/.test(text) || /^0+$/.test(text)) {
    return null;
  }
  return text;
}

// Trims the value. Some rows have values padded with spaces or line breaks.
function clean(value) {
  if (value === null || value === undefined) {
    return null;
  }
  const text = String(value).replace(/\s+/g, " ").trim();
  return text === "" ? null : text;
}

function parseJson(text) {
  try {
    return JSON.parse(text);
  } catch (e) {
    return null;
  }
}

// Socrata dates look like "1987-10-27T00:00:00.000". Only the date is kept.
function formatDate(value) {
  const text = clean(value);
  return text && /^\d{4}-\d{2}-\d{2}/.test(text) ? text.substring(0, 10) : null;
}

// Ranks a row: an active right to transact business first, then an active or reinstated
// Secretary of State status. Higher is better.
function rank(row) {
  const rightToTransact = clean(row.right_to_transact_business_code);
  const sosStatus = clean(row.sos_status_code);
  return (rightToTransact === "A" || rightToTransact === "D" ? 2 : 0) +
    (sosStatus === "A" || sosStatus === "R" ? 1 : 0);
}

function statusDate(row) {
  return formatDate(row.sos_status_date) || formatDate(row.sos_charter_date) || "";
}

// Chooses one row for the taxpayer number, or null when there's none. A few taxpayers have
// more than one row (for example an old and a new Secretary of State registration).
function chooseRow(rows, taxpayerNumber) {
  const candidates = rows.filter((row) => row && clean(row.taxpayer_number) === taxpayerNumber);
  if (candidates.length === 0) {
    log(`The Texas Comptroller has no active franchise taxpayer with number ${taxpayerNumber}.`);
    return null;
  }
  candidates.sort((a, b) => rank(b) - rank(a) || (statusDate(b) > statusDate(a) ? 1 : statusDate(b) < statusDate(a) ? -1 : 0));
  return candidates[0];
}

// Calls the API. Returns the rows for the taxpayer number (possibly none), or null when the
// API can't answer.
function lookUp(taxpayerNumber) {
  const headers = [{ Key: "Accept", Value: "application/json" }];
  if (clean(APP_TOKEN)) {
    headers.push({ Key: "X-App-Token", Value: APP_TOKEN.trim() });
  }

  // starts_with rather than taxpayer_number=...: a few hundred rows have the number padded
  // with a trailing space, which an exact match misses.
  const apiResponse = http.send({
    url: `${TEXAS_URL}?$where=starts_with(taxpayer_number,'${taxpayerNumber}')`,
    method: "GET",
    headers: headers,
  });

  const status = String(apiResponse.HttpStatus || "");
  const body = parseJson(apiResponse.Content);

  if (status === "TooManyRequests") {
    throw new Error("TooManyRequests - data.texas.gov is throttling requests, the record will be retried");
  }

  if ((status === "Forbidden" || status === "Unauthorized") && clean(APP_TOKEN)) {
    throw new Error(`data.texas.gov rejected the app token in the API Key field (HTTP ${status}). ${body && body.message ? body.message : ""}`);
  }

  if (status === "OK" && Array.isArray(body)) {
    return body;
  }

  log(`The Texas Comptroller could not look up taxpayer number ${taxpayerNumber}. HTTP ${status}. ${String(apiResponse.Content || "").substring(0, 200)}`);
  return null;
}

function run() {
  const taxpayerNumber = parseTaxpayerNumber(getValue(TAXPAYER_NUMBER_KEY));
  if (!taxpayerNumber) {
    // No valid taxpayer number on this record (this is also what Test connection hits, because
    // it passes placeholder values instead of real ones).
    return [];
  }

  const cacheKey = `texas:${taxpayerNumber}`;
  const cached = CACHE_MILLISECONDS > 0 ? cache.get(cacheKey) : null;
  let row = cached ? parseJson(String(cached)) : null;

  if (!row) {
    const rows = lookUp(taxpayerNumber);
    if (!rows) {
      return [];
    }
    row = chooseRow(rows, taxpayerNumber);
    if (!row) {
      return [];
    }
    if (CACHE_MILLISECONDS > 0) {
      cache.set(cacheKey, JSON.stringify(row), CACHE_MILLISECONDS);
    }
  }

  const organizationTypeCode = clean(row.taxpayer_organizational_type);
  const sosFileNumber = clean(row.secretary_of_state_sos_or_coa_file_number);
  const sosStatusCode = clean(row.sos_status_code);
  const exemptReasonCode = clean(row.current_exempt_reason_code);

  const data = {
    "texas.taxpayerNumber": taxpayerNumber,
    "texas.name": clean(row.taxpayer_name),
    "texas.address": clean(row.taxpayer_address),
    "texas.city": clean(row.taxpayer_city),
    "texas.state": clean(row.taxpayer_state),
    "texas.zipCode": clean(row.taxpayer_zip),
    "texas.countyCode": clean(row.taxpayer_county_code),
    "texas.organizationType": (organizationTypeCode && ORGANIZATION_TYPES[organizationTypeCode]) || null,
    "texas.organizationTypeCode": organizationTypeCode,
    "texas.sosFileNumber": sosFileNumber,
    "texas.sosFileNumberType": (sosFileNumber && SOS_FILE_NUMBER_TYPES[clean(row.record_type_code)]) || null,
    "texas.sosCharterDate": formatDate(row.sos_charter_date),
    "texas.sosStatus": (sosStatusCode && SOS_STATUSES[sosStatusCode]) || null,
    "texas.sosStatusCode": sosStatusCode,
    "texas.sosStatusDate": formatDate(row.sos_status_date),
    "texas.rightToTransactBusiness": RIGHT_TO_TRANSACT_BUSINESS[clean(row.right_to_transact_business_code)] || null,
    "texas.responsibilityBeginDate": formatDate(row.responsibility_beginning_date),
    "texas.exemptReasonCode": exemptReasonCode === "00" ? null : exemptReasonCode,
    "texas.exemptBeginDate": formatDate(row.exempt_begin_date),
    "texas.naicsCode": clean(row._621111),
  };

  // Leave out values the Comptroller didn't return, so they don't overwrite existing data with blanks.
  Object.keys(data).forEach((key) => {
    if (data[key] === null || data[key] === undefined) {
      delete data[key];
    }
  });

  return [{ Data: data, Score: 100 }];
}

response = JSON.stringify(run());
```

Up: [REST API enricher samples](https://documentation.cluedin.net/govern/rest-api-enricher-samples.md)
