Unofficial Node.js wrapper for the Our Groceries API. Requires Node.js >=20.8.1. This is a Node.js port of the original Python library by Leonardo Merza.
npm install ourgroceriesMinimal usage (environment variables recommended for credentials):
import { OurGroceries } from 'ourgroceries';
const og = new OurGroceries(process.env.OG_USERNAME!, process.env.OG_PASSWORD!);
async function main(): Promise<void> {
await og.login();
const lists = await og.getMyLists();
console.log(lists);
}
main().catch(console.error);Get all lists:
const { shoppingLists } = await og.getMyLists();
shoppingLists.forEach((list) => console.log(`${list.name} (${list.id})`));Get items in a list:
const { list } = await og.getListItems('list-id');
list.items.forEach((item) => {
console.log(`[${item.crossedOff ? '✓' : ' '}] ${item.value}`);
});Add a single item:
await og.addItemToList('list-id', 'Milk', 'Dairy', false, 'Get 2%');Add multiple items:
await og.addItemsToList('list-id', ['Bread', ['Eggs', 'Dairy'], ['Apples', 'Produce', 'Honeycrisp']]);Cross off an item:
await og.toggleItemCrossedOff('list-id', 'item-id', true);Create lists:
await og.createList('Weekly Shopping', 'SHOPPING');
await og.createList('Favorite Recipes', 'RECIPES');Delete list:
await og.deleteList('list-id');Remove all crossed off items:
await og.deleteAllCrossedOffFromList('list-id');See examples/basic-usage.ts. To explore without mutating your lists, run the bundled npm script in read-only mode:
npm run example:readonlyThe script expects OG_USERNAME and OG_PASSWORD environment variables for authentication and skips write operations when OG_READONLY=true is set (this flag is applied automatically by the npm script). Example scripts automatically load these values from a local .env file when it exists.
import { OurGroceries, InvalidLoginException } from 'ourgroceries';
const og = new OurGroceries(process.env.OG_USERNAME!, process.env.OG_PASSWORD!);
async function run(): Promise<void> {
await og.login();
const { shoppingLists } = await og.getMyLists();
shoppingLists.forEach((list) => console.log(list.name, list.id));
}
run().catch(console.error);Logs into Our Groceries. Returns Promise<void>
Gets all lists. Returns Promise<Object>
Gets all category items. Returns Promise<Object>
Items for a specific list. Returns Promise<Object>
Create a new list. Returns Promise<Object>
Create a new category. Returns Promise<Object>
Toggle crossed-off state. Returns Promise<Object>
Add a single item. Returns Promise<Object>
Add multiple items. Returns Promise<Object>
Remove one item. Returns Promise<Object>
Get master list. Returns Promise<Object>
Get category list. Returns Promise<Object>
Delete a list. Returns Promise<Object>
Bulk delete crossed-off items. Returns Promise<Object>
Add item to master list. Returns Promise<Object>
Modify an item. Returns Promise<Object>
InvalidLoginException is thrown on failed login.
- Always call
await og.login()first - Reuse a single
OurGroceriesinstance - Cache frequently used list IDs
- Use
autoCategory=truewhen unsure of category - Wrap API calls in try/catch
- Never hardcode credentials
Missing credentials:
- Ensure
OG_USERNAMEandOG_PASSWORDare set - Check with:
echo $OG_USERNAME echo $OG_PASSWORD
Items not appearing:
- Confirm the correct
listId - Ensure
await og.login()succeeded
Categorization issues:
- Try
autoCategory=true
Transient failures:
- Add simple retry logic with backoff
This project uses Vitest for testing.
Run the test suite:
npm testWatch mode:
npm run test:watchSee CONTRIBUTING.md for guidelines.
MIT
Original Python version: https://github.com/ljmerza/py-our-groceries