USDA / USDA-APIs

Do you have feedback, ideas, or questions for USDA APIs? Use this repository's Issue Tracker to join the discussion.
www.usda.gov/developer
107 stars 16 forks source link

Search with dataType search operator not working #93

Closed Monte307 closed 4 years ago

Monte307 commented 4 years ago

This works (with a valid api key): curl -H "Content-Type:application/json" -d '{"query":"Cheddar cheese", "pageSize": 25}' https://api.nal.usda.gov/fdc/v1/foods/search?api_key=someAPIkey

however, including a "dataType":"Foundation" filter gives this error: status":400,"error":"Bad Request","message":"Invalid request parameter or body"

example: curl -H "Content-Type:application/json" -d '{"query":"Cheddar cheese", "dataType":"Foundation", "pageSize": 25}' https://api.nal.usda.gov/fdc/v1/foods/search?api_key=someAPIkey

littlebunch commented 4 years ago

Try something like {"query":"cheddar cheese","pageNumber":1,"pageSize":1,"dataType":["Branded"]}

The spec is not clear but dataType needs to be represented as an array, i.e []. Also, the example on the website doesn't show this but you should include -XPOST in that cURL call.

buschco commented 4 years ago

Using a string array works for me thanks @littlebunch 😌

littlebunch commented 4 years ago

Also, for a GET request, a csv string should work: https://api.nal.usda.gov/fdc/v1/foods/list?sortBy=fdcId&sortOrder=asc&dataType=Foundation,Branded&pageSize=150&pageNumber=1&api_key=DEMO_KEY&format=abridged

Monte307 commented 4 years ago

that fixed it, thanks littlebunch!