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

Farmers Markets API unavailable #87

Open anshook opened 4 years ago

anshook commented 4 years ago

Is the farmer markets API unavailable? I'm getting 404 error. https://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=94013

LainaJ commented 4 years ago

I got other zipcodes to work with this, but not 94013. Any luck?

msd101psu commented 4 years ago

the zip code 94013 overlaps zip cod 94014, which does return results.

On Fri, Apr 10, 2020 at 6:23 PM Laina Karosic notifications@github.com wrote:

I got other zipcodes to work with this, but not 94013. Any luck?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/USDA/USDA-APIs/issues/87#issuecomment-612244030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQDZ4YB4WI2L3LXQDUVXSDRL6L43ANCNFSM4KGGKCGQ .

anshook commented 4 years ago

Yes, the API is working now. Thank you!

Polibuzz commented 1 year ago

Not sure how you got the API to work, but I'm still attempting to access the API with Flutter/Dart. I obtained a key. Do you have any code you can share on how you accessed the API? Struggling for some time figuring this out. Thanks!

jamesallain commented 1 year ago

Haven't tested it, but this is how you'd do it in Node with TS.

import { handleAxiosError } from "@app/lib";
import axios, { AxiosRequestConfig } from "axios";

export type Root = Response[];

export interface Response {
  fdcId: number;
  description: string;
  dataType: string;
  publicationDate: string;
  foodCode?: string;
  foodNutrients: FoodNutrient[];
  ndbNumber?: string;
}

export interface FoodNutrient {
  number: string;
  name: string;
  amount: number;
  unitName: string;
  derivationCode?: string;
  derivationDescription?: string;
}

/**
 * Returns USDA Food List.
 * @api_docs https://fdc.nal.usda.gov/api-guide.html
 */
export const getUsdaFoodsList = async () => {
  const baseURL = `https://api.nal.usda.gov/fdc/v1/foods/list`;
  const config: AxiosRequestConfig = {
    params: {
      apiKey: process.env.FOOD_DATA_CENTRAL_API_KEY,
    },
  };
  try {
    const response = await axios.get<Response>(baseURL, config);
    return response.data;
  } catch (e) {
    handleAxiosError(e, module.filename);
  }
};