Skip to content

Instantly share code, notes, and snippets.

@russellbodine
Last active August 31, 2017 16:15
Show Gist options
  • Select an option

  • Save russellbodine/531443eda5ccac37a379730c8c5d4a54 to your computer and use it in GitHub Desktop.

Select an option

Save russellbodine/531443eda5ccac37a379730c8c5d4a54 to your computer and use it in GitHub Desktop.

Spending By Category

Route: /api/v2/search/spending_by_category/

Method: POST

This route takes award filters, and returns spending by the defined category/scope. The category is defined by the "category" var, and the scope is defined by is denoted by the "scope" var.

Request

"category": What variable the aggregated_amount is broken up by.

ex: "awarding_agency", "funding_agency", "recipient", "cfda_programs", "industry_codes"

"scope": Scope adds another level of aggregation to category. The possible scopes are dependent on the category var.

  • if category is "awarding_agency" or "funding_agency", possible scopes are "agency", "subagency", or, in the future, "offices"
  • if category is "recipient", possible scopes are (future) "parent_duns", "duns", or (future) "recipient_type"
  • if category is cfda_programs, the scope variable is not included in the request.
  • if category is industry_codes, possible scopes are "psc" or "naics"

filter: how the awards are filtered. The filter object is defined here.

https://gist.github.com/nmonga91/ba0e172b6d3f2aaf50f0ef1bb5d708bc#recipient-location

limit: how many results are returned

page: what page of results are returned

{
	"category": "awarding_agency",
	"scope": "agency",
	"filters": {
	    "award_type_codes": ["A", "B", "03"],
	    "award_ids": [1, 2, 3],
	    "award_amounts": [
		      {
			"lower_bound": 1000000.00,
			"upper_bound": 25000000.00
		      },
		      {
			"upper_bound": 1000000.00
		      },
		      {
			"lower_bound": 500000000.00
		      }
    	     ],..
	"limit": 10
	"page": 1
	}
}

Response (JSON)

{
    "page": 1,
    "scope": "naics",
    "limit": 5,
    "category": "industry_codes",
    "results": [
        {
            "aggregated_amount": 28040,
            "naics_code": "336111",
            "naics_description": "AUTOMOBILE MANUFACTURING"
        }
    ]
}

Errors

Possible HTTP Status Codes:

  • 400 : Missing parameters or limit is not a valid, positive integer
  • 500 : All other errors
{
  "detail": "Sample error message"
}

Other Search Filters

https://github.com/fedspendingtransparency/usaspending-website/wiki/Award-Search-Visualizations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment