jumbo-wrapper
v2.1.0
Published
API Wrapper for Jumbo
Downloads
216
Readme
Unofficial Node.js API wrapper for Jumbo Supermarkten.
Installation
npm install jumbo-wrapper
or
yarn add jumbo-wrapper
then
import { Jumbo } from 'jumbo-wrapper';
Basic usage
// Creates Jumbo object using username and password, set verbose=true if you want to see all requests
const jumbo = new Jumbo({ username, password, verbose: true });
// Gets product as response from ID
const product = await jumbo.product().getProductFromId('67649PAK');
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
.
Product
If I want to find the first 5 product names that match a given query:
import { Jumbo } from 'jumbo-wrapper';
async function findFirstFiveProducts(productName: string) {
const jumbo = new Jumbo();
const products = await jumbo.product().getProductsFromName(productName, {
limit: 5
});
console.log(
products.map((product) => {
return product.product.data.title;
})
);
}
findFirstFiveProducts('melk');
[
'Jumbo Verse Halfvolle Melk 2L',
'Jumbo Verse Halfvolle Melk 1L',
'Jumbo Verse Halfvolle Melk 1, 5L',
'Jumbo Karnemelk & Halfvolle Melk',
'Jumbo Houdbare Halfvolle Melk Voordeelverpakking 6 x 1L'
]
You can also add diet and allergen filters:
import { Jumbo, ProductDietFilter, ProductAllergenFilter } from 'jumbo-wrapper';
async function findLactoseFreeMilk() {
const jumbo = new Jumbo();
const products = await jumbo.product().getProductsFromName('melk', {
limit: 5,
filters: {
diet: [ProductDietFilter.LactoseIntolerant],
allergens: [ProductAllergenFilter.Lactose]
}
});
console.log(
products.map((product) => {
return product.product.data.title;
})
);
}
findLactoseFreeMilk();
[
'Alpro This is Not M*lk Drink Halfvol Gekoeld 1L',
'Alpro This is Not M*lk Drink Vol Gekoeld 1L',
'HiPRO Proteïne Drink Houdbaar Vanille 330ml',
'Alpro Sojadrink Houdbaar 1L',
'Alpro Barista Haver Houdbaar 1L'
]
Keep in mind that Jumbo makes a (good) distinction between the dietary restrictions (lactose intolerant) and allergen restrictions (lactose free). The allergens supplied via the filter are the ones that are not allowed in the product.
Store
If I want to find the name of the store that is closest to a given location:
import { Jumbo } from 'jumbo-wrapper';
async function findJumboStore(longitude: number, latitude: number) {
const jumbo = new Jumbo();
const res = await jumbo.store().getStoresFromLongLat({
long: longitude,
lat: latitude,
limit: 1
});
console.log(res[0].store.data.name);
}
findJumboStore(4.4993409, 51.9106489);
Jumbo Rotterdam Vijf Werelddelen
List
If I want to find the names of the first three lists with the "Winter" list category:
import { Jumbo } from 'jumbo-wrapper';
async function getFirstThreeListsFromCategory(category: string) {
const jumbo = new Jumbo();
const lists = await jumbo.list().getListsByName(category, {
limit: 3
});
const names = lists.items.map((list) => {
return list.title;
});
console.log(names);
}
getFirstThreeListsFromCategory('Winter');
[ 'Budget koken', 'Koken met groente', 'Soepen' ]
Keep in mind that while you don't need to be logged in to view public lists, if you want to view your own list you must login first.
Order
NOTE: Authentication is currently not working, for more info see this issue.
If I want to see the ID of the latest order of my Jumbo account:
import { Jumbo } from 'jumbo-wrapper';
async function getLatestOrder(username: string, password: string) {
const jumbo = new Jumbo(username, password);
const res = await jumbo.order().getMyLatestOrder();
console.log(res.order.data.id);
}
getLatestOrder('[email protected]', 'password');
Keep in mind that you need to be logged in to get your orders, for instructions see Authentication.
Basket
If I want to view my current basket:
import { Jumbo } from 'jumbo-wrapper';
async function getMyBasket(username: string, password: string) {
const jumbo = new Jumbo(username, password);
const basket = await jumbo.basket().getMyBasket();
console.log(basket.prices.total.amount);
}
getMyBasket('[email protected]', 'password');
While this will work when not logged in, it does not really make sense to view the basket of a user that is not logged in.
You can also update your basket as follows:
import { Jumbo } from 'jumbo-wrapper';
async function addMilkToMyBasket(username: string, password: string) {
const jumbo = new Jumbo(username, password);
const updatedBasket = await jumbo.basket().updateBasket({
items: [
{
quantity: 1,
sku: '67649PAK', // SKU for milk
unit: 'pieces' // 'pieces' is often the right choice
}
],
vagueTerms: []
});
console.log(updatedBasket.items[0].sku);
}
addMilkToMyBasket('[email protected]', 'password');
Again, while this will work when not logged in, it does not really make sense to update the basket of a user that is not logged in. Furthermore, the response given by updateBasket
is different from getMyBasket
since the response from updateBasket
will not include any price information, as such, it is recommended to call getMyBasket
after updateBasket
to get the new price information.