API Examples

Simple API calls

The API serves up data published by the Wage and Hour Division of the Department of Labor on investigations of companies. By default it returns the data in JSON. Here's the simplest API call:
http://stopwagetheft.stanford.edu/api/v1/cases

To limit the number of cases, add the limit parameter:
http://stopwagetheft.stanford.edu/api/v1/cases?&limit=10

If the limit parameter is not specified and no other parameters are given to limit the scope to a certain time period or county, then the API by default returns only the first 100 rows. Set limit=0 to get all 200K+ rows.

To make the results easier to read, let's tell the API to return the records in HTML format since we're using the API in a browser:
http://stopwagetheft.stanford.edu/api/v1/cases?limit=10&return_format=html

Other available options for return_format include csv and googledatatable which is directly readable by Google Charts and Maps. Now let's limit the columns returned to the backwages, city, legal name, and state:
http://stopwagetheft.stanford.edu/api/v1/cases?limit=10&return_format=html&columns=legal_name,city,state,backwages

If no column names are specified, then the API by default returns the most commonly used columns. To retrieve all columns use columns=all:
http://stopwagetheft.stanford.edu/api/v1/cases?limit=10&columns=all&return_format=html&city=Santa%20Clara

For a full list of all available columns, see the full list below.

In the above example you can see how to limit the results to a certain city. Here you can see how to limit the results to a specific county:
http://stopwagetheft.stanford.edu/api/v1/cases?columns=all&return_format=html&county=Alameda%20County

The other parameters you can use to limit the results include city, state (CA, MN, etc.), zip, industry, county_fips_code, and state_fips_code (so for example city=San%20Francisco). You can also use a custom where clause in the format of &where=backwages > 20000. The where statement must be SQL code.

To search by company name use the company_name search option which does a full text search on both the legal name and company name. Here's a nationwide search for cases on Cintas:
http://stopwagetheft.stanford.edu/api/v1/cases?&return_format=html&company_name=%27Cintas%27

You can also use sum() or avg() on a column name and the API will automatically aggregate the results, grouping by the other columns. For example, here's the API call to see total backwages and number of cases in Alameda County grouped by city and industry:
http://stopwagetheft.stanford.edu/api/v1/cases?columns=sum(backwages),city,industry,cases_count&return_format=html&county=Alameda%20County

cases_count is a special column that is only available when you are aggregating data. In this case as you would expect it shows the number of cases for each city and industry combination.

Callback JSON function

Depending on how your code is written you may want to have the JSON be returned wrapped in a callback funcion. Here's how you do it:
http://stopwagetheft.stanford.edu/api/v1/cases?columns=sum(backwages),city,industry,cases_count&county=Alameda%20County&callback=your_function

Dates

The API has support for easily limiting the results to certain time periods using the 'dates' option.

All cases with investigative periods ending in 2014:
http://stopwagetheft.stanford.edu/api/v1/cases?dates=2014

All cases with investigative periods ending from 2013 to 2014:
http://stopwagetheft.stanford.edu/api/v1/cases?dates=2013,2014

All cases with investigative periods ending between December 1, 2012 and February 2, 2013:
http://stopwagetheft.stanford.edu/api/v1/cases?dates=2012-12- 01,2013-02-02

List of all available columns

Default Columns:Additional Columns:

case_id

county

trade_name

state_fips_code

legal_name

county_fips_code

street_address

combined_state_county_fips

city

full_naics_code

state

full_naics_description

zip

naics2

latitude

naics2_description

longitude

naics3

industry

naics3_description

backwages

naics4

employees_owed_backwages

naics4_description

civil_money_penalties

minimum_wage_and_overtime_backwages

findings_start_date

employees_owed_minimum_wage_and_overtime_backwages

findings_end_date

minimum_wage_backwages

overtime_backwages

retaliation_backwages

API call for minimum wage violations by industry for CA

http://stopwagetheft.stanford.edu/api/v1/cases?columns=industry,sum(minimum_wage_backwages)&order=minimum_wage_backwages%20desc&where=state=%27CA%27&return_format=googledatatable

Here the API call adds up all the minimum wage backwages by industry, orders the results in descending order by the backwages, limits the results only to California, and returns the results in the "googledatatable" format which can be immediately read by Google Maps and Charts API. After clicking on the link try changing return_format=googledatatable to return_format=html for easier reading in a browser.

Visualization examples using the API

VisualizationApi call used

Google Pie Chart

http://stopwagetheft.stanford.edu/api/v1/cases?columns=industry,sum(minimum_wage_backwages)&order=minimum_wage_backwages%20desc&where=state=%27CA%27&return_format=html

Google Geo Chart

http://stopwagetheft.stanford.edu/api/v1/cases?columns=state,sum(backwages)&return_format=googledatatable&where=state<>''&order=backwages desc

High Maps Counties

http://stopwagetheft.stanford.edu/api/v1/cases?columns=county_fips_code,state,county,sum(backwages)&where=county_fips_code%20is%20not%20null

High Maps States

http://stopwagetheft.stanford.edu/api/v1/cases?columns=state,sum(backwages)&where=state%20is%20not%20null

jQuery Data Tables

http://stopwagetheft.stanford.edu/api/v1/cases?columns=case_id,legal_name,trade_name,employees_owed_backwages,backwages

Crossfilter Test

http://stopwagetheft.stanford.edu/api/v1/cases?columns=city,county,industry,backwages&state=CA&limit=0