Unofficial Node.js API wrapper for Albert Heijn.
npm install albert-heijn-wrapper
or
pnpm i albert-heijn-wrapper
then
import { AH } from 'albert-heijn-wrapper';
// 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.
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
.
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'
]
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
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.
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.