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
109 stars 16 forks source link

The Example for a API Call in the documentation does not work. #72

Open allenind opened 4 years ago

allenind commented 4 years ago

Hello, I'm excited to use this API for the application i'm developing, however the FoodSearch API Call does not work for me. This is what it returns whenever I try it.

curl -H "Content-Type:application/json" -d '{"generalSearchInput":"Cheddar cheese"}' https://api.nal.usda.gov/fdc/v1/search?api_key=MY_API_KEY {"timestamp":"2019-10-31T04:26:28.211+0000","status":400,"error":"Bad Request","message":"JSON parse error: Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: (PushbackInputStream); line: 1, column: 2]","path":"/portal-data/api/v1/search"}

I also would like to know if anyone managed to change the CURL call to a normal HTTP call which can be used in the browser. I would be able to manage to do that if only the example in the docs work. I managed to make the food detail call work. Someone please help. Thank you

littlebunch commented 4 years ago

This call seems to work ok for me. You might want to check yours as the error message seems to indicated a stray ‘ in the json.

Not sure what you mean by a “normal” HTTP call — the cURL call is an HTTP request. If you mean making the call from the browser’s URL bar then that’s difficult to accomplish with POST requests. You probably need to use XHR. There are also a number of Chrome and Firefox REST client plugins.

Gary

On Oct 31, 2019, at 12:29 AM, allenind notifications@github.com wrote:

curl -H "Content-Type:application/json" -d '{"generalSearchInput":"Cheddar cheese"}' https://api.nal.usda.gov/fdc/v1/search?api_key=MY_API_KEY https://api.nal.usda.gov/fdc/v1/search?api_key=MY_API_KEY

allenind commented 4 years ago

This call seems to work ok for me. You might want to check yours as the error message seems to indicated a stray ‘ in the json.

Hello I just checked again and I really can't get the call to work. It says at character 39 which is at curl -H "Content-Type:application/json" <-- the " is being marked as an unexpected character which is weird because all I did was copy the curl in the docs. I didn't manually type the call.

tomb7890 commented 4 years ago

This call works for me too.

I think character 39 may be the double quote character. You could try deleting the double quotes after you paste, and then reinserting them yourself before issuing the curl command. Or just try typing the whole thing out yourself.