@openfoodfacts/openfoodfacts-nodejs
    Preparing search index...

    Class Folksonomy

    Index

    Constructors

    • Parameters

      • fetch: {
            (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
            (input: string | Request | URL, init?: RequestInit): Promise<Response>;
        }
          • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: RequestInfo | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | Request | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | Request | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

      • Optionaloptions: { authToken?: string; baseUrl?: string }

      Returns Folksonomy

    Properties

    client: Client<paths>

    Methods

    • Add a product tag, returns error if the tag already exists

      Parameters

      • tag: {
            comment: string;
            editor?: string;
            k: string;
            last_edit?: string;
            owner: string;
            product: string;
            v: string;
            version: number;
        }

        Tag to add or update with the following fields:

        • k: key
        • v: value
        • product: barcode
        • version: if passed it should be equal to 1
        • owner: user_id of the owner of the tag (empty for public tags)
        • comment: string

          Comment

          
          
        • Optionaleditor?: string

          Editor

        • k: string

          K

        • Optionallast_edit?: string

          Last Edit

        • owner: string

          Owner

          
          
        • product: string

          Product

        • v: string

          V

        • version: number

          Version

          1
          

      Returns Promise<{ detail?: { loc: (string | number)[]; msg: string; type: string }[] }>

      if the tag was added or updated

      const err = await folksonomy.addTag({ k: "vegan", v: "yes", product: "1234567890123", version: 1 });
      if (err) console.error("Error adding tag:", err);
    • Get the list of keys with statistics

      The keys list can be restricted to private tags from some owner.

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: never;
                      header?: never;
                      path?: never;
                      query?: { owner?: string; q?: string };
                  };
                  requestBody?: never;
                  responses: {
                      "200": {
                          content: {
                              "application/json": { count: number; k: string; values: number }[];
                          };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: ((...) | (...))[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              FetchOptions<
                  {
                      parameters: {
                          cookie?: never;
                          header?: never;
                          path?: never;
                          query?: { owner?: string; q?: string };
                      };
                      requestBody?: never;
                      responses: {
                          "200": {
                              content: {
                                  "application/json": { count: number; k: string; values: number }[];
                              };
                              headers: { [name: string]: unknown };
                          };
                          "422": {
                              content: {
                                  "application/json": {
                                      detail?: { loc: (...)[]; msg: string; type: string }[];
                                  };
                              };
                              headers: { [name: string]: unknown };
                          };
                      };
                  },
              >,
              `${string}/${string}`,
          >,
      >

    • Get the list of products that have a key or key=value if value is provided

      Parameters

      • key: string
      • Optionalvalue: string

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: never;
                      header?: never;
                      path?: never;
                      query?: { k?: unknown; owner?: unknown; v?: unknown };
                  };
                  requestBody?: never;
                  responses: {
                      "200": {
                          content: {
                              "application/json": { k: string; product: string; v: string }[];
                          };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: ((...) | (...))[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  params: {
                      query: { k: string; v: string }
                      | { k: string; v?: undefined };
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Get a list of existing tags for a product

      Parameters

      • barcode: string

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: never;
                      header?: never;
                      path: { product: string };
                      query?: { keys?: string; owner?: string };
                  };
                  requestBody?: never;
                  responses: {
                      "200": {
                          content: {
                              "application/json": {
                                  comment: string;
                                  editor?: string;
                                  k: string;
                                  last_edit?: string;
                                  owner: string;
                                  product: string;
                                  v: string;
                                  version: number;
                              }[];
                          };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: ((...) | (...))[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              { params: { path: { product: string } } },
              `${string}/${string}`,
          >,
      >

    • Parameters

      • key: string
      • Optionalopts: { limit?: number; owner?: string; q?: string }

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: never;
                      header?: never;
                      path: { k: string };
                      query?: { limit?: number; owner?: string; q?: string };
                  };
                  requestBody?: never;
                  responses: {
                      "200": {
                          content: {
                              "application/json": { product_count: number; v: string }[];
                          };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: ((...) | (...))[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  params: {
                      path: { k: string };
                      query: { limit?: number; owner?: string; q?: string };
                  };
              },
              `${string}/${string}`,
          >,
      >

    • Authentication: provide user/password and get a bearer token in return

      Parameters

      • username: string

        Open Food Facts user_id (not email)

      • password: string

        user password

      Returns Promise<
          FetchResponse<
              {
                  parameters: {
                      cookie?: never;
                      header?: never;
                      path?: never;
                      query?: never;
                  };
                  requestBody: {
                      content: {
                          "application/x-www-form-urlencoded": {
                              client_id?: string;
                              client_secret?: string;
                              grant_type?: string;
                              password: string;
                              scope: string;
                              username: string;
                          };
                      };
                  };
                  responses: {
                      "200": {
                          content: {
                              "application/json": { access_token: string; token_type: string };
                          };
                          headers: { [name: string]: unknown };
                      };
                      "422": {
                          content: {
                              "application/json": {
                                  detail?: { loc: ((...) | (...))[]; msg: string; type: string }[];
                              };
                          };
                          headers: { [name: string]: unknown };
                      };
                  };
              },
              {
                  body: { password: string; scope: string; username: string };
                  headers: { "Content-Type": string };
              },
              `${string}/${string}`,
          >,
      >

      the bearer token, to be used in later requests with usual "Authorization: bearer token" headers

    • Update a product tag, returns error if the tag does not exist

      Parameters

      • tag: {
            comment: string;
            editor?: string;
            k: string;
            last_edit?: string;
            owner: string;
            product: string;
            v: string;
            version: number;
        }

        Tag to update with the following fields:

        • k: key
        • v: value
        • product: barcode
        • version: version of the tag (must be equal to previous version + 1)
        • owner: user_id of the owner of the tag (empty for public tags)
        • comment: string

          Comment

          
          
        • Optionaleditor?: string

          Editor

        • k: string

          K

        • Optionallast_edit?: string

          Last Edit

        • owner: string

          Owner

          
          
        • product: string

          Product

        • v: string

          V

        • version: number

          Version

          1
          

      Returns Promise<{ detail?: { loc: (string | number)[]; msg: string; type: string }[] }>

      if the tag was added or updated

      const err = await folksonomy.putTag({ k: "vegan", v: "yes", product: "1234567890123", version: 2 });
      if (err) console.error("Error updating tag:", err);
    • Delete a product tag

      Parameters

      • tag: {
            comment: string;
            editor?: string;
            k: string;
            last_edit?: string;
            owner: string;
            product: string;
            v: string;
            version: number;
        } & { version: number }

        Tag to delete with the following fields:

        • k: key
        • v: value
        • product: barcode
        • version: version of the tag [required]
        • owner: user_id of the owner of the tag (empty for public tags)
        • comment: string

          Comment

          
          
        • Optionaleditor?: string

          Editor

        • k: string

          K

        • Optionallast_edit?: string

          Last Edit

        • owner: string

          Owner

          
          
        • product: string

          Product

        • v: string

          V

        • version: number

          Version

          1
          
        • version: number

      Returns Promise<{ detail?: { loc: (string | number)[]; msg: string; type: string }[] }>

      if the tag was deleted