Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

albert-heijn-wrapper

RinseV94MIT3.0.0TypeScript support: included

Node.js wrapper for the Albert Heijn API

readme

Albert Heijn API Wrapper


NPM version NPM license NPM dependencies

npm installnfo

Unofficial Node.js API wrapper for Albert Heijn.

Installation

npm install albert-heijn-wrapper

or

pnpm i albert-heijn-wrapper

then

import { AH } from 'albert-heijn-wrapper';

Basic usage

// Creates AH object
const ah = new AH();
// Gets product as reponse from ID
const product = await ah.product.get(200486);

More information about the functions and parameters can be found on the wiki.

Example usage

For all of these examples, please keep in mind that your function in which you request something should be async since the requests return a Promise.

Products

Let's say I want to find the names of the products called "Brood" but the products have to be gluten free, vegan and I want to sort on ascending price:

import { AH, SearchProductsSortType } from 'albert-heijn-wrapper';

const getGlutenFreeVeganBread = async () => {
  const ah = new AH();

  const { products } = await ah.product.search("Brood", {
    searchInput: {
      // These facets are undocumented
      facets: [
        {
          label: "product.properties.allergie",
          values: {
            values: ["zonder-gluten"]
          }
        },
        {
          label: "product.properties.dieet",
          values: {
            values: ["veganistisch"]
          }
        }
      ],
      page: {
        size: 3
      }
    },
    sortType: SearchProductsSortType.PriceHighLow
  });
  // Map to just the product names
  const names = products.map((product) => product.title);
  console.log(names);
};

getGlutenFreeVeganBread();
[
  'BFree Pita broodjes glutenvrij',
  'Smaakt Lijnzaadcrackers maanzaad less carb',
  'BFree Naan bread gluten free'
]

Stores

Let's say I want to find the address of the nearest store to a given location:

import { AH } from 'albert-heijn-wrapper';

const findNearestStore = async (latitude: number, longitude: number) => {
  const ah = new AH();
  // Find nearest store
  const { result } = await ah.store.search({
    filter: {
      location: {
        latitude,
        longitude
      }
    }
  });
  const store = result?.[0];
  console.log(`${store?.address?.street} ${store?.address?.houseNumber}, ${store?.address?.postalCode} ${store?.address?.city}`);
};

findNearestStore(50, 4);
Westkade 48, 4551BV Sas Van Gent

Authentication

Unfortunately, it is not possible to log in with your personal AH account, which means you won't be able to access your orders. All requests are made as a guest user.

Custom request

If you want to make your own GraphQL request, you can also do that:

import { AH, Stores } from "albert-heijn-wrapper";

const STORES_INFO_QUERY = `
  query StoresInformation($id:Int!) {
    storesInformation(id:$id) {
      id
      name
      address {
        street
        houseNumber
        houseNumberExtra
        postalCode
        city
        countryCode
      }
    }
  }
`;

type StoresInfoResponse = {
  // Type is exported from the wrapper
  storesInformation: Stores;
};

const getStoreInformation = async (id: number) => {
  const ah = new AH();
  const { storesInformation } = await ah.graphql<StoresInfoResponse>(STORES_INFO_QUERY, { id });
  // Response is typed (somewhat) correctly
  console.log(storesInformation.name);
};

// ID from store found from before
getStoreInformation(1809);
AH1809 SAS VAN GENT

The wrapper will automatically provide the access token necessary to make the request.

changelog

albert-heijn-wrapper

3.0.0

Major Changes

  • Switched over to GraphQL API for all requests
  • Removed the functions for the subclasses, they can now be accessed directly (ah.product vs ah.product())
  • Removed the bonus & category subclasses since the GraphQL API does not have 1-to-1 equivalents
  • Reworked the product functions:
    • getProductsFromName is now search and uses a different set of arguments
    • getProductFromId is now get
  • Reworked the recipe functions:
    • getRecipeFromName is now search and uses a different set of arguments
    • getRecipeFromId is now get
  • Reworked the store functions:
    • getStoresFromLocation is now search and uses a different set of arguments
  • Rewrote tests using MSW and Vitest
  • Switched from yarn to pnpm
  • Removed axios and date-fns dependencies, this package now has no external dependencies
  • Updated to Node 22

2.0.1

Patch Changes

  • Fixed error 400 due to missing header

2.0.0

Major changes

  • Updated to major version due to breaking changes
  • Restructured all functions to use objects instead of multiple parameters
  • Added category & bonus objects
  • Added tests
  • Updated readme

1.1.0

Minor changes

  • Restructured all functions to use objects instead of multiple parameters

1.0.0

Major changes

  • Initial release