usaspending-api icon indicating copy to clipboard operation
usaspending-api copied to clipboard

Endpoint [/api/v2/bulk_download/awards/] prime_award_types parameter not optional?

Open nicolassander opened this issue 4 years ago • 3 comments

Hi,

I am sending a POST request to the [/api/v2/bulk_download/awards/] endpoint with the following body:

body = '{ "filters": { "prime_award_types": ["IDV_A", "IDV_B", "IDV_B_A", "IDV_B_B", "IDV_B_C", "IDV_C", "IDV_D", "IDV_E", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "A", "B", "C", "D"], "agency": "all", "date_type": "action_date", "date_range": {"start_date":"2019-01-01", "end_date":"2019-12-31"} } }'

If I don't add the bolded section with prime_award_types I receive a 400 Bad Request error, even though it says prime_award_types is an optional parameter in the GitHub documentation? Am I missing something?

Thanks in advance, Nicolas

nicolassander avatar May 18 '20 18:05 nicolassander

Hello Nicolas,

Thanks for letting us know! In this case, the term "optional" might be a little misleading. Because we perform automatic validation between our API contracts and API endpoints, we mark a parameter as "optional" as long as it's possible to make requests without it, even if there are other validation rules. In this case, the rule in the error message applies: either prime_award_types or sub_award_types must be present.

BrianZito avatar May 18 '20 18:05 BrianZito

Thanks for the very quick reply Brian, I appreciate it!

I was mainly confused, since I tried an example from another user that worked with this body: body <- '{ "award_levels": ["prime_awards"], "filters": { "keyword": "009256819" }, "columns": ["action_date"], "file_format": "csv" }'

Does that work, because the keyword is functioning as another validation rule that can replace prime_award_types or sub_award_types?

nicolassander avatar May 18 '20 19:05 nicolassander

Correct. Keyword actually nullifies all other filters: https://github.com/fedspendingtransparency/usaspending-api/blob/dev/usaspending_api/download/v2/year_limited_downloads.py#L30

BrianZito avatar May 18 '20 20:05 BrianZito